Android4.4中拒绝发送Intent.ACTION_MEDIA_MOUNTED扫描SD卡的广播

来源:互联网 发布:淘宝生e经官网 编辑:程序博客网 时间:2024/05/16 10:43

凡是在我们的项目中,可能会碰到写本地文件,最常用的就是文件,在这之后须要通知体系从头扫描SD卡,
在Android4.4之前也就是以发送一个Action为“Intent.ACTION_MEDIA_MOUNTED”的广播通知履行扫描。如下:



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


但在Android4.4中,则会抛出以下异常:

W/ActivityManager(  498): Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED pid=2269, uid=20016
那是因为Android4.4中限制了体系应用才有权限应用广播通知体系扫描SD卡。

解决体式格式:
应用MediaScannerConnection履行具体文件或文件夹进行扫描。



MediaScannerConnection.scanFile(this, new String[]{Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/" + fileName}, null, null);


转载:http://blog.csdn.net/sgz_china/article/details/24657709

0 0
原创粉丝点击