Unknown URI Error in insertImage

android, mediastore

Solution

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.

Problem

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?

Original source