Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

android - Can't create a directory on /storage/emulated/0 on emulator

I'm trying to create a directory on my android emulator but I can't do it, I already have the permission on manifest write_storage, and I get no erros but mkdir() return false, I verify if external storage is writtable too and it is, it works on physical devices my code:

 /// Cria uma nova pasta para colocar o backup
    File direct = new File(Environment.getExternalStorageDirectory(),
            "/Financas RW Backup");
    try {


        if (!direct.exists()) {
            if(isExternalStorageWritable()&&isExternalStorageReadable()) {
              if(  direct.mkdir()) {
                  fachada.showMessage(ExportImportDB.this," Criado");
              }else{
                  fachada.showMessage(ExportImportDB.this," N?o Criado");
              }
            }
        }
    } catch (Exception e) {
        fachada.showMessage(this, e.toString());
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to options:

  • Downgrade your compileSdkVersion and targetSdkVersion to lower version in your build.gradle
  • Request write permission at runtime is required on Android 6 .

I personally don't advice the first one. For more info check:

Hope this helps!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...