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

后端 未结 2 1046
萌比男神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: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()
    

提交回复
热议问题