androidandroid-intenturiphoto-galleryimage-editor

Android Photo Gallery does not return URI when using intent.ACTION_EDIT


I want to update an image in my app using a external Image Editor. I'm using the following code to start an app to update the image.

private void dispatchAdjustImage(){

    try {
        Integer mImageId = ImageHelper.getImageIdFromRealPath(getString(R.string.imageFilePath) + getString(R.string.imageFileName), getContentResolver());
        Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(mImageId.toString()).build();

        Intent adjustPictureIntent = new Intent();
        adjustPictureIntent.setDataAndType(uri, "image/*");
        adjustPictureIntent.setAction(Intent.ACTION_EDIT);
        adjustPictureIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        adjustPictureIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        startActivityForResult(adjustPictureIntent, REQUEST_IMAGE_ADJUST);
    }catch (ActivityNotFoundException anfe) {
        Global.showDialog(NfScannerActivity.this, getString(R.string.msgErrorAdjustImageAppMissing),
                getString(R.string.msgDownloadPhotoEditor), getString(R.string.textYes),
                getString(R.string.textNo), getString(R.string.motorolaGalleryGooglePlayLink)).show();
    }catch (Exception ex) {
        Toast.makeText(mContext, R.string.msgErrorAdjustImage, Toast.LENGTH_LONG).show();
    }
}

and this is the onActivityResult

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    switch (requestCode)
    {
        case REQUEST_IMAGE_ADJUST:
            getAdjustImageResults(resultCode, intent);
            unprotectViewFields();
            break;
    }

}

private void getAdjustImageResults(int resultCode, Intent intent) {

    if (resultCode == Activity.RESULT_OK)
    {
        clearViewFields();
        try {
            Uri adjustedImageUri = intent.getData();
            String mFullFileName = ImageHelper.getRealPathFromURI(adjustedImageUri, this);
            mImageBitmap = ImageHelper.readImageFromDisk(mFullFileName);
            ImageHelper.deleteImageFromDisk(mFullFileName);
            saveAndLoadImage();

        } catch (Exception e) {
            showErrorDialog(getString(R.string.msgErrorAdjustImage));
        }
    }
}

When I use the Motorola Gallery app to update the picture every thing goes rigth. The Motorla Gallery app starts, I update the picture, save it and when the control is returned to onActivityResult it is possible to get and handle the updated image. The returned intent is like this intent = {Intent@5486} Intent { dat=content://media/external/images/media/22544 }

When I use the Google Photo app the code intent.getData() returns a intent like this intent = {Intent@5486} Intent { typ=image/jpeg } in the debugger. There is no Uri in the returned intent and I'm no able to get the image that was updated. There are no extras also.

What am I missing? Thank you.


Solution

  • The documentation for ACTION_EDIT clearly states:

    Output: nothing.

    Hence, the "Google Photo app" is working correctly.

    You already know the Uri to the image, because you are putting it in the ACTION_EDIT Intent in the first place. So, use that.