SecurityException相关
1、
java.lang.SecurityException: Permission Denial: reading android.support.v4.content.FileProvider uri content://com.wapchief.jpushim.fileProvider/external_files/temp.jpg from pid=14476, uid=10031 requires the provider be exported, or grantUriPermission()
APi24以下版本的日志:
com.wapchief.jpushim E/uri=====: file:///storage/emulated/0/temp.jpg
com.wapchief.jpushim E/uritempFile: file:////storage/emulated/0/small.jpg
APi24以上版本的日志:
com.wapchief.jpushim E/uriBC=====: content://com.wapchief.jpushim.fileProvider/external_files/temp.jpg
com.wapchief.jpushim E/uri=====: content://com.wapchief.jpushim.fileProvider/external_files/temp.jpg
大概意思是需要把提供者导出
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//开启临时权限
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
//重点:针对7.0以上的操作
intent.setClipData(ClipData.newRawUri(MediaStore.EXTRA_OUTPUT, uri));
uritempFile = uri;
} else {
uritempFile = Uri.parse("file://" + "/" + Environment.getExternalStorageDirectory().getPath() + "/" + "small.jpg");
}
2、
java.lang.SecurityException: Permission Denial: opening provider com.wapchief.jpushim.fileProvider from ProcessRecord
大意是说权限之类的没有开放。
解决方案是检查AndroidManifest下Application标签中
android:exported属性是否开启,
查看代码中
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
临时拍照权限是否开启
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.wapchief.jpushim.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
其他参考:
FileProvider
Android7.0调用系统相机拍照、访问相册问题。
相关文章
网友评论