Search code examples
androidandroid-camera-intent

Camera Intent not working with multiple camera apps


In my app I run camera intent to take picture with photo App, with this code below:

Activity activity;
File currentPhotoFile;
Intent capturePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri uri = GenericFileProvider.getUriForFile(activity, activity.getPackageName() + providerSufixName, currentPhotoFile);
capturePhoto.putExtra(MediaStore.EXTRA_OUTPUT, uri);
activity.startActivityForResult(capturePhoto, REQUEST_PHOTO);

And after that I catch the created photo in my activity.onActivityResult function in Activity

If I have only one! photo App on my mobile device - everything works fine.

But! If I installed on my device one more! photo application - the code above is not working :(

In case two photo apps, when I call activity.startActivityForResult - I see andoid system dialog with list of all available photo apps. (like Intent.createChooser calling). I select from it, preferable photo app and tap "JUST ONCE". Selected application runs, I take picture inside it and press Ok button for returning back to my App. At this moment I recieve callback to my onActivityResult with my code: REQUEST_PHOTO but with requestCode = RESULT_CANCELED. And that's all :(

Why it's not working? And how I can resolve this issue and use camera intent with more than one photo application?


Solution

  • The problem was that in manifest I have option: android:launchMode="singleInstance" for my activity.

    <activity
                android:name="MyActivity"
                android:launchMode="singleInstance"
    >
    

    For solving above issue you should remove singleInstance option from manifest file (or replace it within singleTask option). This is resolve the issue and onActivityResult is properly working.