Using an emulator with the camera, don't have a device to use


#1

Here is the message I get.

03/02 15:31:57: Launching app
adb push C:\AndroidApps\BigNerdRanchExercise\BDCriminalIntent\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.bignerdranch.android.bdcriminalintent adb shell pm install -r "/data/local/tmp/com.bignerdranch.android.bdcriminalintent"
Success

$ adb shell am start -n “com.bignerdranch.android.bdcriminalintent/com.bignerdranch.android.bdcriminalintent.CrimeListActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet…Waiting for process to come online
Waiting for process to come online
Waiting for process to come online
Waiting for process to come online
Connected to process 3197 on device emulator-5554
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
E/EGL_emulation: tid 3228: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9eaf1120, error=EGL_BAD_MATCH
E/EGL_emulation: tid 3228: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x910240a0, error=EGL_BAD_MATCH
D/AndroidRuntime: Shutting down VM

              --------- beginning of crash

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bignerdranch.android.bdcriminalintent, PID: 3197
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.bignerdranch.android.bdcriminalintent/files/Pictures/IMG_ce845d3b-eefd-45b1-b2eb-ef2a73010f4b.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:8909)
at android.content.Intent.prepareToLeaveProcess(Intent.java:8894)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
at android.app.Activity.startActivityForResult(Activity.java:4224)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.support.v4.app.ActivityCompatJB.startActivityForResult(ActivityCompatJB.java:31)
at android.support.v4.app.ActivityCompat.startActivityForResult(ActivityCompat.java:169)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:934)
at android.support.v4.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:1043)
at android.support.v4.app.Fragment.startActivityForResult(Fragment.java:951)
at android.support.v4.app.Fragment.startActivityForResult(Fragment.java:940)
at com.bignerdranch.android.bdcriminalintent.CrimeFragment$6.onClick(CrimeFragment.java:203)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
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:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Application terminated.


#2

Apps targeting Nougat are not allowed to expose file:// URIs to other apps. There are two ways to resolve this:

  • Change your targetSdkVersion to 23 or lower. This is not ideal, but it will stop this crash.

  • Use a FileProvider to expose the destination file to the camera app.


#3

Thanks I changed the targetSdkVersion to 23 and it worked. Now I will use the FileProvider to expose the destination.