使用如下方法刷新

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

更多相关文章

  1. android Timer使用方法
  2. Android 使用git下载源码报错解决方法
  3. Android中的onCreateOptionsMenu()方法和onOptionsItemSelected()方
  4. 关于androidSDK更新缓慢的解决方法(以W7为例)
  5. 执行Android JUnit测试出现java.net.SocketException: Permissio
  6. [android]notifyDataSetChanged方法
  7. Android后台发送短信方法
  8. Android 检查应用是否安装、唤起的方法
  9. Could not find com.android.tools.build:aapt2:3.3.2-5309881.

随机推荐

  1. RxAndroid入门-传智播客
  2. android 混淆 去除第三方jar
  3. Android开发系列(三)
  4. 【记录】 Android(安卓)双卡手机获取两个
  5. 解决:Error: Could not find gradle wrapp
  6. Activity的启动模式(android:launchMode)
  7. WebKit – WebKit For Android
  8. Ubuntu 16.04环境下使用Clion 2019.1.4 g
  9. How to decompile Google Android(安卓).
  10. Android遍历文件Listfile返回值为null问