public void readFilesFromStorage(File storage) {
if (storage != null && storage.isDirectory()) {
Log.d("StorageInfo", "Storage: " + storage.getAbsolutePath());
listFilesInDirectory(storage);
} else {
Log.d("StorageInfo", "Invalid storage path.");
}
}
public void listAllExternalStorages() {
File[] storages = ContextCompat.getExternalFilesDirs(this, null);
for (File storage : storages) {
if (storage != null) {
String state = Environment.getExternalStorageState(storage);
if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
readFilesFromStorage(storage);
}
}
}
}
public void listFilesInDirectory(File directory) {
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
Log.d("FileList", "Directory: " + file.getPath());
listFilesInDirectory(file);
} else {
Log.d("FileList", "File: " + file.getPath() + " Size: " + file.length());
}
}
} else {
Log.d("FileList", "No files found in directory.");
}
}
Почему когда я читаю директорию, которую андроид сам создал, то он видит файлы
2024-04-29 15:40:03.722 32513-32513 StorageInfo com.example.application D Storage: /storage/emulated/0/Android/data/com.example.application/files
2024-04-29 15:40:03.739 32513-32513 StorageInfo com.example.application D Storage: /storage/98EC9E58EC9E310C/Android/data/com.example.application/files
2024-04-29 15:40:03.743 32513-32513 FileList com.example.application D File: /storage/98EC9E58EC9E310C/Android/data/com.example.application/files/test.png Size: 2679
но если я вызываю метод так
File usbRoot = new File("/storage/98EC9E58EC9E310C");
listFilesInDirectory(usbRoot);
то не получается прочитать директорию?