Reputation: 101
I've got an app that accepts images from the image gallery (via share menu). My app starts, and I do this:
Bundle bundle = getIntent().getExtras();
Object obj = bundle.get("android.intent.extra.STREAM");
While debugging, Eclipse is reporting the object obj is of type 'Uri@StringUri' (???) and inside it somewhere is the string 'content://media/external/images/media/992'. Anybody know what type of object obj is so I can typecast it? And what's the string about? IE, how do I get to the image data?
Upvotes: 2
Views: 2047
Reputation: 7981
It is of type Uri
, a Universal Resource Identifier.
content://media/external/images/media/992
is the URI of the image. To turn it into a direct file system path, pass the URI to this method which I found elsewhere on this site:
// Convert the image URI to the direct file system path of the image file
public String getRealPathFromURI(Uri contentUri) {
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
Upvotes: 2