在Android 7.0上,当我想在日志中打开相机时,我看到了:
EventBus: Could not dispatch event: class pl.eltegps.smokkomunikator.event.PhotoRequestedEvent to subscribing class class pl.eltegps.smokkomunikator.ui.activity.MainActivity
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/pl.eltegps.smokkomunikator/images/gps_TEMP.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9483)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9468)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525)
at android.app.Activity.startActivityForResult(Activity.java:4399)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:4358)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:871)
at pl.eltegps.smokkomunikator.ui.activity.MainActivity.onPhotoRequestedEvent(MainActivity.java:399)
at java.lang.reflect.Method.invoke(Native Method)
at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:485)
at org.greenrobot.eventbus.EventBus.postToSubscription(EventBus.java:416)
at org.greenrobot.eventbus.EventBus.postSingleEventForEventType(EventBus.java:397)
at org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:370)
at org.greenrobot.eventbus.EventBus.post(EventBus.java:251)
at pl.eltegps.smokkomunikator.ui.fragment.NewMessageFragment.photo(NewMessageFragment.java:259)
at pl.eltegps.smokkomunikator.ui.fragment.NewMessageFragment$$ViewBinder$1.doClick(NewMessageFragment$$ViewBinder.java:28)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:6199)
at android.view.View$PerformClick.run(View.java:23647)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
在android 4.4.2上,我检查它是否正常工作,但在新的android上它并没有正常工作,我不知道为什么......
答案 0 :(得分:0)
这是我在7.0上测试时遇到的问题。好像你不能在没有使用内容提供者的情况下直接在7.0上使用getUri()。
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
FileProvider.getUriForFile(getActivity(), getActivity().getApplicationContext().getPackageName() + ".provider", f));
您必须使用它并在项目的xml目录中添加provider.xml。
this链接有详细解释。