Why Images.Media.insertImage return null

前端 未结 7 507
耶瑟儿~
耶瑟儿~ 2020-12-03 20:55

I have some code where I run the method MediaStore.Images.Media.insertImage (inserting it from a source not a file name), This code saves the image to the MediaStore and ret

7条回答
  •  -上瘾入骨i
    2020-12-03 21:36

    MediaStore.Images.Media.insertImage is actually accessing external storage to save the image.

    Some important reminders which might be causing your app to fail:

    1. A USB connection will block SD card usage if in Mass Storage mode.

    2. There may be other factors that might lead to an SD card being inaccessible, so make sure that you can access the SD card using a file browser first.

    3. Make sure that your permissions are correctly configured with android.permission.WRITE_EXTERNAL_STORAGE

    Posting this here for completeness, as I was getting a null from insertImage, and the cause was 1.

提交回复
热议问题