问题
I'm trying to display all images saved on a specific folder on the gallery, in Android Q getExternalStoragePublicDirectory
method is deprecated and not working, How can I get the path of a folder in Android Q?
@Override
protected ArrayList<Photo> doInBackground(Void... voids) {
ArrayList<Photo> photo = new ArrayList<>();
File downloadsFolder = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//
} else {
downloadsFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES + "/FolderName");
}
Photo s;
if (downloadsFolder != null && downloadsFolder.exists()) {
File[] files = downloadsFolder.listFiles();
if (files != null) {
for (File file : files) {
s = new Photo();
s.setName(file.getName());
s.setUri(Uri.fromFile(file));
photo.add(s);
}
}
}
return photo;
}
来源:https://stackoverflow.com/questions/57451973/how-to-get-the-path-of-a-specific-folder-in-android-q