Use Environment.getExternalStorageDirectory on Android 10
This commit is contained in:
parent
497af31e52
commit
adeee18ecd
@ -164,8 +164,13 @@ public class MediaLibrary {
|
|||||||
private static ArrayList<String> discoverDefaultMediaPaths(Context context) {
|
private static ArrayList<String> discoverDefaultMediaPaths(Context context) {
|
||||||
ArrayList<String> defaultPaths = new ArrayList<>();
|
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.Q) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
// 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()) {
|
for (File file : context.getExternalMediaDirs()) {
|
||||||
// Seems to happen on some Samsung 5.x devices. :-(
|
// Seems to happen on some Samsung 5.x devices. :-(
|
||||||
if (file == null)
|
if (file == null)
|
||||||
|
@ -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
|
* 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
|
* 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.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -212,7 +213,20 @@ public class FileUtils {
|
|||||||
public static File getFilesystemBrowseStart(Context context) {
|
public static File getFilesystemBrowseStart(Context context) {
|
||||||
SharedPreferences prefs = SharedPrefHelper.getSettings(context);
|
SharedPreferences prefs = SharedPrefHelper.getSettings(context);
|
||||||
String folder = prefs.getString(PrefKeys.FILESYSTEM_BROWSE_START, PrefDefaults.FILESYSTEM_BROWSE_START);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user