java.io.ioexception: open failed: einval (Invalid argument) when saving a image to external storage

后端 未结 2 1044
萌比男神i
萌比男神i 2020-12-29 06:11

This is my code:

private boolean writeToSD(Bitmap bm, String url) {
    if (canIWriteOnSD()) {
        File sd = Environment.getExternalStorageDirectory();
          


        
相关标签:
2条回答
  • 2020-12-29 06:35

    The string url contains illegal characters for a filename. You'll need to cleanup the filename by removing the illegal characters.

    0 讨论(0)
  • 2020-12-29 06:48

    Really tricky error since Android 28 works just fine when trying to write a filename with ? or : in the name, but Android 22 for instance would blow up. Just run a couple of replacements in the filename like:

    File(filename.replace(":", "").replace("?", "") [...])
    

    and then you're good to run

    file.createNewFile()
    
    0 讨论(0)
提交回复
热议问题