1

I know how to pick photo from gallery and it always work.

The code to pick photo from gallery:

Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, REQ_GALLERY);

And code to handle result in onActivityResult():

Uri uri = data.getData();
Cursor cursor = getContext().getContentResolver().query(uri, new String[] {
    MediaStore.Images.Media.DATA,
}, null, null, null);
if (cursor == null) return false;
if (cursor.moveToFirst()) {
    String path = cursor.getString(0);
    if (path != null) {
           startPhotoEdit(new File(path), output, requestCode);
           cursor.close();
           return true;
    }
}
cursor.close();

This time I pick them from Google Photos and the photo is still stored in cloud and not downloaded to local yet. After I pick one and it starts downloading like that:

photo_downloading

When the download task finished and return to my application, the _data column in cursor which always contains photo path is null.

Can someone help me, please.

Shion Tang
  • 11
  • 2
  • This code works for Google photos https://stackoverflow.com/a/44193985/1448357 – Gaurav Aug 02 '17 at 08:49
  • @Gaurav Thanks! Your answer is similar to what I want. But I prefer this more effective. [https://stackoverflow.com/q/32326558/8404007](https://stackoverflow.com/q/32326558/8404007) – Shion Tang Aug 02 '17 at 10:34

1 Answers1

0

I finally find that when photo from cloud is picked, its Uri is different. Like this:

content://com.google.android.apps.photos.contentprovider/1/1/mediakey%3A%2Flocal%253A131b7978-cc48-4206-8561-d18f99421551/ORIGINAL/NONE/2134743478

It contains mediakey instead of content in normal Uri.

So, this might be helpful:

getContentResolver().openInputStream(uri);

Shion Tang
  • 11
  • 2