I am trying to get an image from the gallery app from one of the folders from the Google+ synced photos. After selecting the image, the Uri is being passed back correctly. But when I try to get the actual path of that image on the storage device, so that I can use it, it crashes. The problem seems to be specifically with the picasa content provider.
Tested on Nexus S and Nexus 7, and other devices as well.
E/AndroidRuntime(14572): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.google.android.gallery3d.provider/picasa/item/5427003652908228690 }}
Here, the dat field seems to be correctly passing the Uri, but when I try to fetch the image's location, it crashes with the following error.
W/GalleryProvider(14381): unsupported column: _data
Seems that the content provider for Picasa albums doesn't have a _data field.
The code for getting the location is:
// imageUri is the Uri from above. String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(imageUri, proj,null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String filePath = cursor.getString(column_index); cursor.close();
The only columns that seem to be supported for this image are: [user_account, picasa_id, _display_name, _size, mime_type, datetaken, latitude, longitude, orientation]
How do we get the actual location of this image. And if we are not supposed to work with this image, these images shouldn't be shown to the user in the first place.
The Intent to launch the gallery app is:
Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT);
I wasted now lots of hours and now i found a solution which works in all cases without any magic downloading in special threads or something. The following method returns a stream from the content which the user selected and this works with everything in the wild.
I faced the same problem about year ago.. I show you my solution (code is quite messy, please refactor it). So, you have the image URI which was returned from gallery:
And now we need function to download image:
ImageInfo is my class to store path to image and its orientation.
Below trick worked for me, what i am doing here is if there is any authority url in URI, then i am creating a temporary image using below code & returning the Content URI of the same.
I have answered similar question here as well..
Based on @drindt answer, below codes give downloaded temporary
File
path from Google Photo cloud-synced-but-not-in-device file.I used this approach, works fine for me, hope this will helps you ....
ACTIVITYRESULT_CHOOSEPICTURE is the int you use when calling startActivity(intent, requestCode);
if above code doesn't work than just refer this link... it will surly shows the way
http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/
Finally ended with a classic solution...By using Document.util, which covers all authority :-1-Inside your onActivityResult():-
2- Create class DocumentUtils:-
}
3- Also you will need following function in ImageLoader.java:-