targetSdkVersion 为安卓14时,优化安卓14上媒体重选逻辑(根据谷歌官方推荐写法) #2837
+288
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
安卓14设备上,如果媒体授权时用户选了
选择部分照片和视频
选项的话,之后每次进入相册,都会无提示自动弹出系统的选择允许此应用访问的照片和视频
弹窗。这个逻辑对用户来说不太友好,查了谷歌官方文档,官方推荐在无媒体授权且有READ_MEDIA_VISUAL_USER_SELECTED授权
时,提示用户,让用户去选择是否重选媒体文件。官方文档:https://developer.android.google.cn/about/versions/14/changes/partial-photo-video-access?hl=zh-cn#media-reselection
我做的修改:
MediaReselectionTipView
,用于安卓14上的媒体重选提示PictureSelectorFragment
中权限判断相关逻辑,细化出需要处理媒体重选的情况并处理一些情况说明:
MediaReselectionTipView
的样式配置使用了BottomNavBarStyle
中背景色、预览正常字体颜色、预览选中字体颜色、预览正常字体大小ps_fragment_selector.xml
布局中新加了MediaReselectionTipView
,有自己自定义布局的,需要在自己的布局中合适位置加入 MediaReselectionTipView,否则会报错NPEdemo 中各样式效果: