我正在尝试显示保存在图库中特定文件夹中的所有图像,在 Android Q 中,getExternalStoragePublicDirectory
方法已被弃用且无法正常工作,如何获取 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;
}