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://stackoverflow.com/questions/4646913/android-how-to-use-mediascannerconnection-scanfile/5814533#5814533

http://www.apkbus.com/android-124798-1-1.html

android添加图片到本地,无法即使刷新的解决方法,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。