Android4.4之前:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://" + file)));  

在4.4中会报权限异常

Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=2269, uid=20016
那是因为Android4.4中限制了系统应用才有权限使用广播通知系统扫描SD卡

之后

  

 public static void refreshAlbum(Context context, File file) {


        try {
            MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), file.getName(), null);
        } catch(FileNotFoundException e) {
            e.printStackTrace();
        }


        context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
    }

 

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-04-14
  • 2021-11-20
  • 2021-11-22
  • 2021-11-22
  • 2021-12-26
猜你喜欢
  • 2021-12-27
  • 2021-11-24
  • 2021-11-10
  • 2021-07-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案