I'm trying to list files from directories but it seems like the directories are empty:
File dir = Environment.getExternalStorageDirectory();
String path = dir.getAbsolutePath();
File carpeta = new File(path);
String[] listado = carpeta.list();
if (listado == null || listado.length == 0) {
Toast.makeText(this, "No hay elementos dentro de la carpeta actual", Toast.LENGTH_SHORT).show();
System.out.println("No hay elementos dentro de la carpeta actual");
return;
}
else {
for (int i=0; i< listado.length; i++) {
System.out.println(listado[i]);
}
}
I have checked the directories and if they have files, it is internal memory and the app also has the permissions. I got it by giving Storage permissions manually, is there a way to automate it?
Your code should work, but remember that even if you require permissions for read/write (
WRITE_EXTERNAL_STORAGE
) it is very important that the permission is also defined within yourAndroidManifest.xml