简体   繁体   中英

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 file 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".

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