Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
2015-02-28 15:52
671 查看
当在Android4.4上进行图片的扫描功能开发时一般会使用:sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory()+ picPath)));的广播
因为Android4.4中限制了系统应用才有权限使用广播通知系统扫描SD卡,所以会抛题目异常。
解决方法:使用MediaScannerConnection执行具体文件或文件夹进行扫描,核心代码如下:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 判断SDK版本是不是4.4或者高于4.4
String[] paths = new String[]{Environment.getExternalStorageDirectory().toString()};
MediaScannerConnection.scanFile(mContext, paths, null, null);
} else {
final Intent intent;
if (f.isDirectory()) {
intent = new Intent(Intent.ACTION_MEDIA_MOUNTED);
intent.setClassName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver");
intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));
Log.v(LOG_TAG, "directory changed, send broadcast:" + intent.toString());
} else {
intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(path)));
Log.v(LOG_TAG, "file changed, send broadcast:" + intent.toString());
}
mContext.sendBroadcast(intent);
}
可参考: http://blog.csdn.net/eoeAndroida/article/details/41806525 http://www.itstrike.cn/Question/0fd8e064-dadc-487b-be73-de6bb0e329b3.html http://stackoverflow.com/questions/24072489/java-lang-securityexception-permission-denial-not-allowed-to-send-broadcast-an
http://www.thinksaas.cn/group/topic/219309/
因为Android4.4中限制了系统应用才有权限使用广播通知系统扫描SD卡,所以会抛题目异常。
解决方法:使用MediaScannerConnection执行具体文件或文件夹进行扫描,核心代码如下:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 判断SDK版本是不是4.4或者高于4.4
String[] paths = new String[]{Environment.getExternalStorageDirectory().toString()};
MediaScannerConnection.scanFile(mContext, paths, null, null);
} else {
final Intent intent;
if (f.isDirectory()) {
intent = new Intent(Intent.ACTION_MEDIA_MOUNTED);
intent.setClassName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver");
intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));
Log.v(LOG_TAG, "directory changed, send broadcast:" + intent.toString());
} else {
intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(path)));
Log.v(LOG_TAG, "file changed, send broadcast:" + intent.toString());
}
mContext.sendBroadcast(intent);
}
可参考: http://blog.csdn.net/eoeAndroida/article/details/41806525 http://www.itstrike.cn/Question/0fd8e064-dadc-487b-be73-de6bb0e329b3.html http://stackoverflow.com/questions/24072489/java-lang-securityexception-permission-denial-not-allowed-to-send-broadcast-an
http://www.thinksaas.cn/group/topic/219309/
相关文章推荐
- 关于Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
- 解决 not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
- Android问题(二)not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
- 解决android4.4中 Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
- Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED解决方法
- Android问题集锦之三十八:not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
- 解决android4.4中 Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
- Permission Denial: not allowed to send broadcast android.intent.action.SCREEN_OFF
- Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.HEADSET_PLUG
- Android问题集锦之三十八:not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
- Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED解决方法
- 【Android】not allowed to send broadcast android.intent.action.MEDIA_MOUNTED
- 关于 Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from 错误原因
- not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid
- Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=2269,
- 异常问题not allowed to send broadcast android.intent.action.BATTERY_CHANGED可能的一种解决方案
- Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.int
- android java.lang.SecurityException: Permission Denial: not allowed to send broadcast
- android中bug——not allowed to send broadcast android.intent.action.phone_state
- Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.int