I am trying to access the directory programmatically, but listFiles()returns null even if I have files in this directory. I created a directory in the root of the application using the command mkdir, and I clicked the images into the directory using the command adb push. Access to all other directories of the application and listFiles()returns null only in the directory that I made.
Application directories (the contents of all other directories, except for the photo, are shown listFiles()):
dex
inbox
pics
right
I have included the necessary permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
A method that goes through directories (when recursion reaches the pics directory root.listFiles() = null:
HashMap<File, Bitmap> imageReader(File root) {
HashMap<File, Bitmap> returnList = new HashMap<>();
HashMap<File, Bitmap> holderList;
File[] files = root.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
holderList = imageReader(files[i]);
returnList.putAll(holderList);
} else {
if (files[i].getName().endsWith(".jpg") || files[i].getName().endsWith(".jpeg")) {
returnList.put(files[i], getFileBitmap(files[i]));
}
}
}
return returnList;
}
EDIT: UID and GID are the same for all directories
root@generic_x86:/data/user/0/com.erkki.hellogridview/files/instant-run
ls -n
-rw------- 10058 10058 5 2016-07-25 15:56 active
drwx------ 10058 10058 2016-07-25 15:38 dex
drwxrwxrwx 10058 10058 2016-07-25 15:56 inbox
drwxrwxrwx 10058 10058 2016-07-26 13:08 pics
drwxr--r-- 10058 10058 2016-07-26 15:18 pics2
drwx------ 10058 10058 2016-07-25 15:56 right
source
share