Understanding Storage Permissions in Android 13: A Guide
Written on
Chapter 1: Overview of Storage Permissions
In every new Android release post-Version 8, developers must adapt to new protocols for accessing user-sensitive data. With each iteration, Google either phases out old APIs or introduces new ones.
As a focal point, this discussion will delve into storage permissions, specifically the previous Read_External_Storage_Permission and Write_External_Storage_Permission. With Android 10, the Write_External_Storage_Permission was deprecated in favor of Scoped Storage. Subsequently, Google added the All_Files_Access feature, which necessitates clarification during the app bundle upload to the Play Store.
Section 1.1: Transitioning to New Permissions
In Android 13, if you aim to access images from the gallery, you must request access specifically for images. The same applies to videos and audio files.
Historically, with Read_External_Storage_Permission and Write_External_Storage_Permission, developers had the ability to access a broad range of files, including images, videos, audio, and documents. However, the current framework has shifted.
Three new permissions have been introduced in Android 13: READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, and READ_MEDIA_AUDIO. If your application relied on READ_EXTERNAL_STORAGE to access files, you will now need to utilize one of these new permissions. If a user with Android 13 has previously granted this permission, everything remains functional. However, if not, requests for READ_EXTERNAL_STORAGE will be disregarded, necessitating adjustments to your app.
Subsection 1.1.1: Implementing Permission Requests
To request permissions in Android 13, you should add the following line to your Manifest file:
private val readImagePermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
Manifest.permission.READ_MEDIA_IMAGESelse
Manifest.permission.READ_EXTERNAL_STORAGE
Then, check for permission as follows:
if(ContextCompat.checkSelfPermission(this, readImagePermission) == PackageManager.PERMISSION_GRANTED)
{
// Permission granted
} else {
// Request permission here
}
This approach applies similarly to audio and video permissions as well.
Google has also introduced the Photo Picker library, which I'll aim to elaborate on in a future article.
Chapter 2: Important Resources
For a deeper understanding of storage permissions in Android 13, check out this video: "Storage Permission Not Showing in Android 13 - YouTube".
Additionally, this video, "How to Allow Storage Permission in Android 13 - YouTube," provides practical guidance on managing these permissions effectively.
I hope this tutorial assists you in adapting to the new permissions system. Thank you for your support!