• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

startActivityForResult

Hey,

The LogCat is recording that Line 67 is failing (highlighted below) -


Code:
private void selectImage() {

    final CharSequence[] options = { "Take Photo", "Choose from Gallery","Cancel" };
    AlertDialog.Builder builder = new AlertDialog.Builder(CameraActivity.this);
    builder.setTitle("Add Photo");
    builder.setItems(options, new DialogInterface.OnClickListener() {

        [USER=1021285]@override[/USER]
        public void onClick(DialogInterface dialog, int item) {
            if (options[item].equals("Take Photo"))
            {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                startActivityForResult(intent, 1);
            }
            else if (options[item].equals("Choose from Gallery"))
            {
                Intent intent = new   Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, 2);
            }
            else if (options[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();
}

Here's the Logcat section (highlighted in red) -

Code:
FATAL EXCEPTION: main
                                                                            Process: com.example.nb.crunchnpeel, PID: 18014
                                                                            android.os.FileUriExposedException: file:///storage/emulated/0/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:9530)
                                                                                at android.content.Intent.prepareToLeaveProcess(Intent.java:9515)
                                                                                at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525)
                                                                                at android.app.Activity.startActivityForResult(Activity.java:4403)
                                                                                at android.app.Activity.startActivityForResult(Activity.java:4362)
                                                                                at com.example.nb.crunchnpeel.CameraActivity$2.onClick(CameraActivity.java:67)
                                                                                at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1259)
                                                                                at android.widget.AdapterView.performItemClick(AdapterView.java:339)
                                                                                at android.widget.AbsListView.performItemClick(AbsListView.java:1718)
                                                                                at android.widget.AbsListView$PerformClick.run(AbsListView.java:4184)
                                                                                at android.widget.AbsListView.onTouchUp(AbsListView.java:6769)
                                                                                at android.widget.AbsListView.onTouchEvent(AbsListView.java:6516)
                                                                                at android.widget.ListView.onTouchEvent(ListView.java:1648)
                                                                                at android.view.View.dispatchTouchEvent(View.java:10779)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2859)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2535)
                                                                                at android.widget.AbsListView.dispatchTouchEvent(AbsListView.java:6420)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2865)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2550)
                                                                                at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:607)
                                                                                at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1890)
                                                                                at android.app.Dialog.dispatchTouchEvent(Dialog.java:1046)
                                                                                at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:569)
                                                                                at android.view.View.dispatchPointerEvent(View.java:11008)
                                                                                at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5162)
                                                                                at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5014)
                                                                                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4539)
                                                                                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4592)
                                                                                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4558)
                                                                                at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4691)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4566)
                                                                                at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4748)
                                                                                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4539)
                                                                                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4592)
                                                                                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4558)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4566)
                                                                                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4539)
                                                                                at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7098)
                                                                                at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7030)
                                                                                at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6991)
                                                                                at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7208)
01-05 16:55:23.194 18014-18014/com.example.nb.crunchnpeel E/AndroidRuntime:     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                                                                                at android.os.MessageQueue.nativePollOnce(Native Method)
                                                                                at android.os.MessageQueue.next(MessageQueue.java:323)
                                                                                at android.os.Looper.loop(Looper.java:136)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                                                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)

What's going on? This is trying to open the camera.

Nick.
 
Last edited by a moderator:
You're passing a URI to an Activity, which isn't allowed

https://developer.android.com/reference/android/os/FileUriExposedException.html

"The exception that is thrown when an application exposes a file:// Uri to another app.

This exposure is discouraged since the receiving app may not have access to the shared path. For example, the receiving app may not have requested the READ_EXTERNAL_STORAGE runtime permission, or the platform may be sharing the Uri across user profile boundaries.

Instead, apps should use content:// Uris so the platform can extend temporary permission for the receiving app to access the resource.

This is only thrown for applications targeting N or higher. Applications targeting earlier SDK versions are allowed to share file:// Uri, but it's strongly discouraged."
 
Back
Top Bottom