我的应用程序面向 api 级别 32。在 Android 13 设备上运行时,ActivityResultContracts.RequestMultiplePermissions() 始终返回 PERMISSION_DENIED,即使用户按下“允许”也是如此。
此外,当检查设置->应用->权限时,图像、音频和视频权限将被授予。
文档明确指出,针对 api 级别 < 33 的应用程序应该继续请求 READ_EXTERNAL_DEVICE,并且图像、音频和视频将被自动授予
尝试允许 READ_EXTERNAL_STORAGE 权限。
预计会打开图库。
实际上,权限被拒绝了。
最佳答案
显然,从 android 13 及更高版本开始,您需要为 READ_MEDIA_VIDEO、READ_MEDIA_IMAGES、READ_MEDIA_AUDIO 设置权限,而不仅仅是请求 READ_EXTERNAL_STORAGE 将单独工作,甚至不会显示在设置的权限页面中
<!-- Required only if your app needs to access images or photos
that other apps created. -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<!-- Required only if your app needs to access videos
that other apps created. -->
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<!-- Required only if your app needs to access audio files
that other apps created. -->
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<!-- If your app doesn't need to access media files that other apps created,
set the "maxSdkVersion" attribute to "28" instead. -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />
关于android-13 - READ_EXTERNAL_STORAGE 在 Android 13 设备上始终被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74468281/