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 originally wrote
a bunch of custom thumbnail generation code, but I'd prefer not to use
it if I can use a built in function.
I'm a bit stumped.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en