** EDIT
Rather than an sdcard, i'm accessing it via adapters through the usb port, so it might be better to consider it as an usb drive.
After a lot of struggle and research, i was able to find a way to reach the path to the sdcard (USB drive) i was working with. In general, the path is /mnt/media_rw/XXXX-XXXX (where XXXX-XXXX is a code of the sdcard (USB drive)).
The thing is, i'm trying to read some files that are in there, but when i call
new File("/mnt/media_rw/XXXX-XXXX").listFiles();
i get that returns a null array. I'm pretty certain that has files inside it, since i have a phone where this works, but in that phone, the path it's not "mnt/media_rw/XXXX-XXXX". Using the same path as in that phone does not work.
I've reached that path through this post How can I get the list of mounted external storage of android device
I have 2 permissions: READ_EXTERNAL_STORAGE and READ_PHONE_STATE. I had to add them bot in the manifest and programmatically (don't know why only works when add them in both, but not separated).
** ADDED
public static String findFileInStorages(String filename) throws Exception {
List<StorageUtils.StorageInfo> storageList = StorageUtils.getStorageList(); // Here i get 2 paths: 1) /storage/emulated/0; 2) /mnt/media_rw/XXXX-XXXX
for(int i = 0; i < storageList.size(); i++) {
String pathToFile = findFileWithBasePath(new File(storageList.get(i).path, filename);
if (pathToFile != null) return pathToFile;
}
throw new Exception("Couldn't find file");
}
public static String findFileWithBasePath(File file, String fileName) throws Exception {
File listFile[] = file.listFiles();
String outputFile = null;
if (listFile != null && listFile.length > 0) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
outputFile = findFileWithBasePath(listFile[i], fileName);
} else {
if(listFile[i].getName().contains(fileName)) {
return listFile[i].getAbsolutePath();
}
}
if (outputFile != null) return outputFile;
}
}
return null;
}
The "getStorageList()" method and "StorageUtils" and "StorangeInfo" classes are in the link above. i didn't change a thing of the code in it.
If there is anything i can add, just ask it.
Thanks