如何在 android kitkat 中刷新图库?
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
我尝试了上面的方法,但它在 android 4.4 中没有刷新。以编程方式添加/删除图像时如何刷新图库?
最佳答案
这对我有用:)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File("folderPATH", "fileName");
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
appContext.sendBroadcast(mediaScanIntent);
} else {
appContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/" + "FOLDER_TO_REFRESH")));
}
希望对您有所帮助:)
关于android - 在android kitkat中刷新画廊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20265438/