0

I'm developing an app which requires the user to take a Picture. I create a file for saving the image. So I call the Intent like this:

if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
    // Create the File where the photo should go
    File photoFile = null;
    try {
        photoFile = createImageFile();
    } catch (IOException ex) {
        // Error occurred while creating the File
        Toast.makeText(FormActivity.this, "No se pudo crear el archivo", Toast.LENGTH_SHORT).show();
    }
    // Continue only if the File was successfully created
    if (photoFile != null) {
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photoFile));
        startActivityForResult(takePictureIntent, ACTION_IMAGE_CAPTURE);
    }
}

And then, I want to read the file. With something like this

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
options.inDither = true;
b = BitmapFactory.decodeFile(new File(mCurrentPhotoPath).getAbsolutePath(), options);

This works nice in Android 4 and 5. However, in Android 6 the Bitmap is null. I think this happens because when ActivityResult is called, the File has not been written yet. I say this because the bitmap loading code is called onResume. And if I lock the device and unlock it again, the code works.

If I add a validation for a file size greater than 0, the code is not executed in Android 6. How can I solve this?

Javier Enríquez
  • 630
  • 1
  • 9
  • 25
  • 1
    what about run time check permission – saeed Apr 19 '16 at 04:07
  • http://stackoverflow.com/a/33162451/3790150,http://stackoverflow.com/a/33139165/3790150 – saeed Apr 19 '16 at 04:10
  • Please use bitmap like Bitmap imageBitmap = (Bitmap) extras.get("data"); at on activity result and save bitmap as file. Also if you are target sdk 23 and then please check permission runtime for writing file – Rajesh N Apr 19 '16 at 04:21
  • I don't think its a permission issue because the image is saved, just not immediately. So, I should asume that setting `EXTRA_OUTPUT` is not recommended? – Javier Enríquez Apr 19 '16 at 17:31

0 Answers0