- Forum-Beiträge: 650
02.07.2024, 21:19:53 via Website
02.07.2024 21:19:53 via Website
Hallo zusammen
Ich möchte in meiner App den Speicher auslesen und alle Dateien anzeigen.
// startet das auslesen des Speichers
private void listFiles() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
File externalStorageDir = null; //getExternalStorageDirectory();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
externalStorageDir = Environment.getRootDirectory();
}
List<File> fileList = new ArrayList<>();
getAllFiles(externalStorageDir, fileList);
for (File file : fileList) {
System.out.println(file.getAbsolutePath());
}
} else {
Toast.makeText(this, "External storage is not mounted", Toast.LENGTH_SHORT).show();
}
}
private void getAllFiles(File dir, List<File> fileList) {
File[] files = dir.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
getAllFiles(file, fileList);
} else {
fileList.add(file);
}
Wie muss Enviroment lauten, damit der Pfad auf den App Speicher lautet?
externalStorageDir = Environment.getRootDirectory();
Gruss Renato