Android MediaStore.Images.Media.getBitmap returns error
ContentResolver cr = getContentResolver(); Uri pic = Uri.parse("content://media/external/images/media/3"); Bitmap bm = Media.getBitmap(cr,pic);
The above code is written in onCreate method of my Activity class. It throws the following error:
08-30 12:27:22.352: WARN/System.err(245): java.io.FileNotFoundException: No content provider: [content://media/external/images/media/3]
What could be wrong? The f开发者_JAVA技巧ile in question is there because I launched Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI) in another method and got back the Uri of the picked image from the returned intent.
You should do something like :
private String getPath(Uri uri) {
String[] data = { MediaStore.Images.Media.DATA };
CursorLoader loader = new CursorLoader(context, uri, data, null, null, null);
Cursor cursor = loader.loadInBackground();
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
Okay, I found the issue. I was giving the wrong Uri. I was giving "[content://blahblah]" where as I should have given "content://blahblah".
精彩评论