In API 33 (Android 13), granular media permissions have been introduced, and developers have to request these granular permissions instead of READ_EXTERNAL_STORAGE
.
READ_MEDIA_AUDIO
is one such granular permission. This permission exists only in API level 33 , so my question is, which permission should I request in the manifest?
Since my app has minSDK = 21
, should I request both READ_EXTERNAL_STORAGE
and READ_MEDIA_AUDIO
in the manifest. Or should I only request READ_EXTERNAL_STORAGE
and that will cover READ_MEDIA_AUDIO
? (At runtime, of course, I will ask for either of the permission based on the SDK_INT
of the device.)
CodePudding user response:
You should add both permissions to your manifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
The READ_MEDIA_AUDIO
permission will work only for devices with Android 13 or above.
Then, as you wrote, you should handle each case of the SDK (this section may be helpful for other developers):
- for the SDK 21 and 22 the permission will be added automatically after the app installation
- starting from the SDK 23 you should use the runtime permissions for the
READ_EXTERNAL_STORAGE
permission (https://developer.android.com/training/permissions/requesting) - there were changes related to the external storage starting from Android 11 (SDK 30), however, you still can download audio files using the same
READ_EXTERNAL_STORAGE
permission. Regarding the changes, for example the directoryRecordings
exists only from the SDK 31 (source: https://developer.android.com/training/data-storage/shared/media#media_store) - starting from the SDK 33 request the granulated permission
READ_MEDIA_AUDIO