Unable to create directory on / storage / emulated / 0 on emulator

I am trying to create a directory on my Android emulator, but I can’t do it, I already have permission to write_storage manifest and I don’t get any erros, but mkdir () returns false, I check if the external storage is the same, too, it works on physical devices of 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()); } 
+6
source share
2 answers

You have options:

  • compileSdkVersion your compileSdkVersion and targetSdkVersion to a lower version in build.gradle
  • On-demand write permission at runtime is required on Android 6 .

I personally do not recommend the first. More details:

Hope this helps!

+5
source

I have a similar problem was fixed using mkdirs instead of mkdir

0
source

All Articles