Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown URI Error in insertImage

Trying saving bitmap into gallery

Bitmap bitmap = Bitmap.createBitmap(surfaceView.getWidth(), surfaceView.getHeight(), Bitmap.Config.ARGB_8888);
surfaceView.draw(new Canvas(bitmap));
MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "foo" , "bar");

I ran the application on the emulator and got an UnsupportedOperationException.

07-25 22:27:48.719: E/MediaStore(1918): Failed to insert image
07-25 22:27:48.719: E/MediaStore(1918): java.lang.UnsupportedOperationException: Unknown URI: content://media/external/images/media
07-25 22:27:48.719: E/MediaStore(1918):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:168)
07-25 22:27:48.719: E/MediaStore(1918):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
07-25 22:27:48.719: E/MediaStore(1918):     at android.content.ContentProviderProxy.insert(ContentProviderNative.java:415)
07-25 22:27:48.719: E/MediaStore(1918):     at android.content.ContentResolver.insert(ContentResolver.java:730)
07-25 22:27:48.719: E/MediaStore(1918):     at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:801)

Unfortunately I don't have any android device right now, is this because of the emulator? Or another reason?

like image 437
fish potato Avatar asked Jul 25 '13 14:07

fish potato


2 Answers

I have had similar problems when the directory DCIM/Camera didn't exist on the sdcard. Creating the directory (and having the permission) has resolved a similar problem for me.

like image 113
thomasd Avatar answered Nov 16 '22 13:11

thomasd


I found that it was an emulator problem. I had not set up the emulator correctly. To fix this what I did was to open the android Virtual device manager, edit the AVD and add a SD Card size. Once I have done that I start the AVD and take a picture. After I have done that, it started working.

like image 3
Steve Avatar answered Nov 16 '22 12:11

Steve