Search code examples
androidgoogle-plusandroid-contentprovidergoogle-photos

Download image from new Google+ (plus) Photos Application


Recently Google added the Photos app for Google+ (plus) and it shows up when you launch an Intent to choose an image. However, if I select an image from Google+ Photos and try to use it in my application none of my current logic is able to return a usable URI or URL to actually get an image that I can download and manipulate. I'm currently using the "common" methods to try to manipulate the URI that can be found here on Stack Overflow and elsewhere. I can provide code if needed, but at this point I think it's kind of irrelevant since it works well for everything else except this new app. Any ideas on how to get a usable image?

The URI looks something like the following:

content://com.google.android.apps.photos.content/0/https%3A%2F%2Flh5.googleusercontent.com%<a bunch of letters and numbers here>

The MediaColumns.DATA info always returns null and the MediaColumns.DISPLAY_NAME always returns image.jpg no matter what I select from the Google Photos app. If I try to paste everything from https to the end in my browser, nothing comes up. Not sure how to get usable info from this.


Solution

  • When receiving the data intent, you should use the contentResolver to get the photos. Here's what you should do:

    String url = intent.getData().toString();
    Bitmap bitmap = null;
    InputStream is = null;
    if (url.startsWith("content://com.google.android.apps.photos.content")){
           is = getContentResolver().openInputStream(Uri.parse(url));
           bitmap = BitmapFactory.decodeStream(is);
    }