android添加图片到本地,无法即使刷新的解决方法

使用如下方法刷新

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

android添加图片到本地,无法即使刷新的解决方法,布布扣,bubuko.com

android添加图片到本地,无法即使刷新的解决方法

上一篇:Android 百度地图频繁添加覆盖物后刷新出现地图闪烁问题(个人)


下一篇:【IOS】IAP 内置购买 Your first In-App Purchase(s) must be submitted with a new app version. Select them fr