使用如下方法刷新
filePath - 图片完整路径
if(hasKitkat()){ MediaScannerConnection.scanFile(activity, new String[] { outDir.getAbsolutePath() }, new String[]{ "image/*" }, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { activity.sendBroadcast(new Intent(android.hardware.Camera.ACTION_NEW_PICTURE, uri)); activity.sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", uri)); } }); scanPhotos(outFile.getAbsolutePath(), activity); // 实际起作用的方法 }else{ activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory()))); }
public static void scanPhotos(String filePath, Context context) { Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri uri = Uri.fromFile(new File(filePath)); intent.setData(uri); context.sendBroadcast(intent); }
public static boolean hasKitkat() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; }
参考:
http://*.com/questions/4646913/android-how-to-use-mediascannerconnection-scanfile/5814533#5814533
http://www.apkbus.com/android-124798-1-1.html