Unknown URI Error in insertImage

Attempting to save a bitmap to the 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 an emulator and received a 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 an Android device right now, is it because of the emulator? Or another reason?

+6
source share
3 answers

I had similar problems when the DCIM / Camera directory did not exist on the SD card. Creating a directory (and with permission) solved a similar problem for me.

+2
source

I found this to be an emulator problem. I set up the emulator correctly. To fix this, I decided to open the Android Virtual Device Manager, edit the AVD and add the size of the SD card. As soon as I did this, I launched AVD and took a picture. After that I started to work.

+1
source

He worked for the Galaxy Nexus. So this could be a problem with the emulator.

0
source

Source: https://habr.com/ru/post/950275/


All Articles