崩溃手机
机型: 华为
系统: Android 4.4.2
崩溃日志
Process: com.huawei.camera, PID: 31496
java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{44394a00 31496:com.huawei.camera/u0a11} (pid=31496, uid=10011) that is not exported from uid 10166
at android.os.Parcel.readException(Parcel.java:1468)
at android.os.Parcel.readException(Parcel.java:1422)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2865)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4685)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2361)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1459)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:916)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:679)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:655)
at com.huawei.camera.util.ActivityUtil.openOutputStream(ActivityUtil.java:72)
at com.huawei.camera.util.ActivityUtil.writeDataToUri(ActivityUtil.java:81)
at com.huawei.camera.ui.page.ReviewPage.handlePhotoDataResult(ReviewPage.java:117)
at com.huawei.camera.ui.page.ReviewPage.doReturnToCaller(ReviewPage.java:107)
at com.huawei.camera.ui.page.ReviewPage.access$000(ReviewPage.java:33)
at com.huawei.camera.ui.page.ReviewPage$1.onClick(ReviewPage.java:49)
at android.view.View.performClick(View.java:4446)
at android.view.View$PerformClick.run(View.java:18480)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5315)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
解决办法
我是照着这个博客的方法解决的。
总结下就是两种方法。
1.在开启相机前进行兼容性判断
uri是照片的uri,intent是开启相机的intent
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
intent.setClipData(ClipData.newRawUri("", uri));
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION|Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
2.直接给予系统相机所需要的权限
grantUriPermission("com.huawei.camera", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
网友评论