I'm trying to create an auto-backup app in which all photos taken from the Camera will be uploaded to Cloudinary.
Using Android Device Monitor, I found that the storage location for Camera images in my Android Studio is "/storage/0804-0A1C/DCIM/Camera" as shown below:
However, I am unable to read from this directory because of permissions(?). I made sure to add WRITE_EXTERNAL_STORAGE to the manifest but canRead() returns false. What can I do to gain access with my code?
class UploadPhotos implements Runnable {
@Override
public void run() {
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
System.out.println("--------dir " + storageDir + " " + storageDir.canRead());
String[] files = storageDir.list();
if (files != null) {
System.out.println("code does not get this far, files == null");
for (String file : files) {
if (new File(storageDir + file).isDirectory()) {
String[] subFiles = new File(storageDir + file).list();
for (int i = 0; i < subFiles.length; i++) {
if (new File(subFiles[i]).isFile()) {
uploadFile(new File(subFiles[i]));
}
}
} else {
uploadFile(new File(file));
}
}
}
}
}