Use Environment.getExternalStorageDirectory on Android 10

This commit is contained in:
Adrian Ulrich 2020-01-19 09:19:07 +01:00
parent 497af31e52
commit adeee18ecd
2 changed files with 23 additions and 4 deletions

View File

@ -164,8 +164,13 @@ public class MediaLibrary {
private static ArrayList<String> discoverDefaultMediaPaths(Context context) {
ArrayList<String> defaultPaths = new ArrayList<>();
// Try to discover media paths using getExternalMediaDirs() on 5.x and newer
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// Running on a platform which enforces scoped access, so we blindly accept all dirs.
for (File file : context.getExternalMediaDirs()) {
defaultPaths.add(file.getAbsolutePath());
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Try to discover media paths using getExternalMediaDirs() on 5.x and newer
for (File file : context.getExternalMediaDirs()) {
// Seems to happen on some Samsung 5.x devices. :-(
if (file == null)

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2016 Adrian Ulrich <adrian@blinkenlights.ch>
* Copyright (C) 2015-2020 Adrian Ulrich <adrian@blinkenlights.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,6 +29,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
@ -212,7 +213,20 @@ public class FileUtils {
public static File getFilesystemBrowseStart(Context context) {
SharedPreferences prefs = SharedPrefHelper.getSettings(context);
String folder = prefs.getString(PrefKeys.FILESYSTEM_BROWSE_START, PrefDefaults.FILESYSTEM_BROWSE_START);
return new File( folder.equals("") ? Environment.getExternalStorageDirectory().getAbsolutePath() : folder );
if (folder.equals("")) {
folder = Environment.getExternalStorageDirectory().getAbsolutePath();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// If we are running on a platform which enforces scoped access, try to find
// the suggested media dir instead.
for (File p : context.getExternalMediaDirs()) {
folder = p.getAbsolutePath();
break;
}
}
}
return new File(folder);
}
/**