存储访问框架来获取外部存储路径,获取公共目录下指定类型文件夹的路径
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
// 获取存储访问框架的根路径
File file = context.getExternalFilesDir(null);
// 获取存储访问框架下指定类型文件夹的路径
file = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
String path = file.getAbsolutePath();
} else {
// 获取公共目录下指定类型文件夹的路径
File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String path = file.getAbsolutePath();
}