Search code examples
androidandroid-intentandroid-activity

Activity result code always 0 (cancel) when there is two or more activities to handle intent


I have a problem, when I startActivityForResult to take picure, resultCode is always Activity.RESULT_CANCELED (0) if there is two or more camera apps that can handle that intent (app chooser appears). But if I set one of them as default app and next time it doesn't offer me a chooser, everything works fine, and it takes picture and detects it in a onActivityResult in my fragment that started startActivityForResult(). Same thing happens when I try to open gallery to select picture. If there are two gallery apps, I choose either one of them, picture selection result is always 0. This is the code I use to start camera app:

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
      startActivityForResult(takePictureIntent, AppConstants.TAKE_PICURE_CAMERA_REQUEST_CODE);
  }

Solution

  • I had the same issue. In my manifest my <activity> element had launchMode="singleTask", but I changed said attribute value to "singleTop" and that solved the problem.