您的位置:首页 > 移动开发 > Android开发

not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid

2017-01-17 00:11 681 查看
我在今天画一个画布的时候存储的时候发现了这个问题 

加读写权限并不能解决问题

在stackoverfollow中找到了一个办法,在高版本中使用ACTION_MEDIA_SCANNER_SCAN_FILE去通知系统重新扫描文件。代码如下:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

//这里主要进行了一下判断呢  在高版本的时候通知系统重重新扫描文件
Intent mediaScanIntent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(file); //out is your output file
mediaScanIntent.setData(contentUri);
Main2Activity.this.sendBroadcast(mediaScanIntent);
}else {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MEDIA_MOUNTED);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android
相关文章推荐