android 10 以上 提出了分区概念,在android 10中使用requestLegacyExternalStorage=true可以取消分区,但是在android11上面必须要有分区,在选择相册中,需要使用外部内容url(EXTERNAL_CONTENT_URI)
在android11中文件存储的位置:
1.图片(包括照片和屏幕截图),存储在 DCIM/ 和 Pictures/ 目录中。系统将这些文件添加到 MediaStore.Images 表格中。
2.视频,存储在 DCIM/、Movies/ 和 Pictures/ 目录中。系统将这些文件添加到 MediaStore.Video 表格中。
3.音频文件,存储在 Alarms/、Audiobooks/、Music/、Notifications/、Podcasts/ 和 Ringtones/ 目录中,以及位于 Music/ 或 Movies/ 目录中的音频播放列表中。系统将这些文件添加到 MediaStore.Audio 表格中。
4.下载的文件,存储在 Download/ 目录中。在搭载 Android 10(API 级别 29)及更高版本的设备上,这些文件存储在 MediaStore.Downloads 表格中。此表格在 Android 9(API 级别 28)及更低版本中不可用。
在项目中
1.最好使用targetSDK=29避免很多android10.11的适配文件
2.在application中添加android:requestLegacyExternalStorage="true"
3.获取相册的地方修改为
public static final Intent choosePicture() {
if (Build.VERSION.SDK_INT >=30) {// Android 11 (API level 30)
return new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
} else {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
return Intent.createChooser(intent, null);
}
}
网友评论