4

At my software developing company, we are developing multiples Android apps that use the camera to take pictures. We found an unsolvable problem in two Sony devices: The onActivityResult method is not called by the Camera Intent, so there is no event triggered on the app to handle the image file and continue the app process. We don't know why and neither how to handle the problem.

This is the way we use to call the camera, from a Fragment:

public void takePicture() {

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + ".jpg";
        File storageDir = new File(PATH_TO_IMAGES);

        File imageFile = new File(storageDir.getAbsolutePath(), imageFileName);

        mImagePath = imageFile.getAbsolutePath();
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));

        mIsTakingPicture = true;
        startActivityForResult(takePictureIntent, TAKE_PICTURE);

    }
}

The questions are:

  1. Have you experienced this problem with some devices? Specifically, the Sony Xperia Devices? The Sony devices that present this problem were Sony Xperia E4 and Sony C2104.

  2. How do we handle the problem before launching the camera? How can we tell the onActivityResult method was not called back?

BSMP
  • 4,596
  • 8
  • 33
  • 44
Tito Leiva
  • 892
  • 1
  • 12
  • 29
  • You don't have to do any thing in onActivityRes since you already had defile the file for uri of image,if the file uri was not define by you then the onActivityResult will give you the file uri. As you already defined the file uri before starting the intent , you will get a null value in onActivityResult, One more thing is that if you are starting the intent from the fragment then you have to define the onActivityResult on the parent Activity. Right now i will suggest you to right your code of onActivityResult inside onResume of the fragment or define onActivityResult in your parent activity. – HAXM Apr 25 '16 at 11:28
  • I understand your approach, but i don't think is the best solution to handle the picture in the onResume, despite you don't need to use the onActivityResult params. This method was created for that and try to fool the fragment's lifecycle is never a good idea. Most of the smartphones tested works succesfully, but those Sony Xperia are the only exception. – Tito Leiva Apr 27 '16 at 15:31
  • 1
    The best approach is to define the onActivityResult in your parent Activity as well, from there only you will get the Intent value for your fragment, for onActivityResult(), you just understand the first part but didn't understand my second part. hope now you got it – HAXM Apr 28 '16 at 02:39
  • It works, thanks man! – Tito Leiva Apr 28 '16 at 20:37

0 Answers0