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());
}
I had the same problem with Android 10. I solved it by adding android:requestLegacyExternalStorage="true"
to my <application>
element in the manifest
Note: We can also use context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
. There are other directory type constants in Environment like DIRECTORY_MUSIC
, DIRECTORY_MOVIES
etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With