简体   繁体   中英

Thumbnails and picking picasa images from gallery on ICS

I'm having a hard time getting Thumbnails.getThumbnail to work with picasa photos on a Nexus S running ICS. Everything else seems to work including getting the original image from picasa and displaying it, but the getThumbnail doesn't seem to work. I'm getting the following errors when attempting to use it:

E/MiniThumbFile( 1852): Got exception when reading magic, id = 5745625138093120418, disk full or mount read-only? class java.lang.IllegalArgumentException
W/MediaProvider(  540): original media doesn't exist or it's canceled.

The disk is not full, it is read-write, the app has external storage write permissions, and the picture does indeed exist on picasa (I can view it through the android Gallery app).

The same code works fine on Android 2.3, but it follows a slightly different path, as 2.3 seems to download a copy of the photo and hand you the actual local file:// uri to the newly downloaded image, rather than hand you a content:// uri.

This is the main meat of the code in question:

  public void addImage(Uri uri, boolean local)
  {
     ContentResolver resolver = getContentResolver();
     Uri actualUri = uri;

     Log.d(TAG, "addImage: original uri: " + uri.toString());

     if(local) {
        try {
           List<String> uriPath = uri.getPathSegments();
           String contentUri = Media.insertImage(resolver, uri.getPath(), uriPath.get(uriPath.size()-1), new String());
           actualUri = Uri.parse(contentUri);
        }
        catch(java.io.FileNotFoundException ex) {
           Log.e(TAG, "FileNotFoundException: ");
           ex.printStackTrace();
        }
     }

     Log.d(TAG, "addImage: actual uri: " + actualUri.toString());

     List<String> uriPath = actualUri.getPathSegments();
     long imageId = Long.parseLong(uriPath.get(uriPath.size() -1));

     Bitmap thumb = Thumbnails.getThumbnail(resolver, imageId, Thumbnails.MINI_KIND, null);
     if(thumb == null) {
        Log.e(TAG, "Failed to get thumbnail for our image.");
        Toast toast = Toast.makeText(getApplicationContext(), "Failed to get thumbnail for image. Please try again.", Toast.LENGTH_SHORT);
        toast.show();
        return;
     }

     uris.add(uri);
     bmps.add(thumb);
     notifyDataSetChanged();
  }

That method is called when ever a new photo is added to the application's "collection" of photos. When its known to be a local image (ie: if a photo was taken from inside the app, or onActivityResult's data argument is null), the local parameter is set to true and I attempt to get a content:// uri back from the media content provider so we can get a valid image id to pass to Thumbnails.getThumbnail. That code works fine for images gotten from the Camera app (via startActivityForResult), as well as images from the gallery that are stored locally on the device.

I'm a bit stumped.

https://developers.google.com/picasa-web/docs/2.0/reference#media_group

If you are having a hard time in android getting to the thumbnails, note the above link and api and the media:group/media:thumbnail tag in the atom feed. Thats the parent element or the container of the thumbnails refered to in this post

So, in order to process thumbs in android, if you can structure your code to actually use the api ( picasa feeds / photos / media:group etc. ) you may have fewer bugs issues like the present one.

Sample google/ android / picasa code

api ref

another api ref

Had the same problem and it was an import/package problem.

Make sure to use the correct Thumbnail class. There are two. One for Video and one for Images.

MediaStore.Images.Thumbnails
MediaStore.Video.Thumbnails

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM