Android4.4中拒绝发送Intent.ACTION_MEDIA_MOUNTED扫描SD卡的广播
2016-05-05 09:29
405 查看
通常在我们的项目中,可能会遇到写本地文件,最常用的就是图片文件,在这之后需要通知系统重新扫描SD卡,
在Android4.4之前也就是以发送一个Action为“Intent.ACTION_MEDIA_MOUNTED”的广播通知执行扫描。如下:
但在Android4.4中,则会抛出以下异常:
W/ActivityManager( 498): Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=2269, uid=20016
那是因为Android4.4中限制了系统应用才有权限使用广播通知系统扫描SD卡。
解决方式:
使用MediaScannerConnection执行具体文件或文件夹进行扫描。
转载:http://blog.csdn.net/sgz_china/article/details/24657709
在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 from 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
相关文章推荐
- Android中WebView在加载网页的时候,怎样应用本地的CSS效果?就是说怎样把本地的CSS嵌入到HTML中
- android AudioManager类详解
- android学习中--弹球游戏
- android:layout_gravity 和android:gravit的区别?
- android第一章 环境介绍
- Android failed creating starting window
- android studio 代码混淆
- Android基础之Activity生命周期
- android Intent组件属性
- android用jsoup解析html详细教程
- Android 开发,乐视手机调试
- Android NDK R9d 安装
- android handler工作原理
- Android 横竖屏+碎片的应用
- Android-获取服务getContext().getSystemService()
- Android中Parcelable接口用法
- MessageDigest简介和android密码加密算法
- Android 下拉列表Popupwindow
- Android官方开发文档Training系列课程中文版:高效显示位图之加载大位图
- android 更新时应用未安装