虽然
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
仅限于 4.4 的系统应用程序
这是另一种解决方案..传递您已删除或添加的图像的路径,如果图像被删除,则图像传递true
,或者如果将图像添加到图库,则传递false
。
/**
* Scanning the file in the Gallery database
*
* @param path
* @param isDelete
*/
private void scanFile(String path, final boolean isDelete) {
try {
MediaScannerConnection.scanFile(context, new String[] { path },
null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
if (isDelete) {
if (uri != null) {
context.getContentResolver().delete(uri,
null, null);
}
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}