最近在做个相机功能。把照片保存到系统相册之后。利用sendBroadcast去通知ACTION_MEDIA_SCANNER_SCAN_FILE总是无效。
代码如下:
String url=MediaStore.Images.Media.insertImage(getContentResolver(), picture, "", "");
Uri uri= Uri.parse(url);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,uri));
发现总是没有更新系统相册!
设备是HTC G18,求大家指点下
------解决思路----------------------
试试这个,应该好使
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
祝你成功!