android.os.FileUriExposedException: file:///storage/emulated/0/ehcda exposed beyond app through...

近日在写通过相机获取头像并上传的逻辑时,发现调取相机老是出错,以下是错误log:

Process: com.edt.edtadmin, PID: 17070
     android.os.FileUriExposedException: file:///storage/emulated/0/ehcda exposed beyond app through ClipData.Item.getUri()
         at android.os.StrictMode.onFileUriExposed(StrictMode.java:1816)
         at android.net.Uri.checkFileUriExposed(Uri.java:2350)
         at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
         at android.content.Intent.prepareToLeaveProcess(Intent.java:9052)
         at android.content.Intent.prepareToLeaveProcess(Intent.java:9037)
         at android.app.Instrumentation.execStartActivity(Instrumentation.java:1530)
         at android.app.Activity.startActivityForResult(Activity.java:4391)
         at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:54)
         at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
         at android.app.Activity.startActivityForResult(Activity.java:4335)
         at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:708)
         at com.edt.framework_common.utils.PhotoUtils.startCapture(PhotoUtils.java:43)
         at com.edt.edtadmin.section.home.activity.MyActivity$2.CameraClick(MyActivity.java:131)
         at com.edt.framework_common.utils.CameraDialog$1.onClick(CameraDialog.java:64)
         at android.view.View.performClick(View.java:5646)
         at android.view.View$PerformClick.run(View.java:22459)
         at android.os.Handler.handleCallback(Handler.java:761)
         at android.os.Handler.dispatchMessage(Handler.java:98)
         at android.os.Looper.loop(Looper.java:156)
         at android.app.ActivityThread.main(ActivityThread.java:6523)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

通过网上查询知道,原来android NN收回了对访问文件权限。若要在应用间共享文件,您应发送一项 content://URI,并授予 URI 临时访问权限。
万能的大神已经给了解决的办法,我就不再重复造车了,下面是解决这个问题的办法:
解决 Android N 上报android.os.FileUriExposedException

你可能感兴趣的:(bug)