If you work in Android development, you've probably noticed that file management has become a real headache lately. Gone are the days when we could write to any corner of the SD card without asking anyone's permission; now we're faced with a much more closed ecosystem where Google has restored order to prevent any app from snooping on other apps' data.
This change, known as Scoped Storage, isn't arbitrary; it's a security measure designed to give users control. To avoid having your app rejected from the store, it's crucial to understand that file architecture has evolved into a system based on the purpose of the file and not simply on its physical location.
The concept of Scoped Storage and its impact
Starting with Android 10, and becoming fully established in Android 11, the operating system began forcing applications to work within their own "pond." This means that, by default, an app only has access to its own environment. application-specific directory, usually located in Android/datawhich is invisible to the average user and other apps.
The idea is simple: each application should manage its own affairs without interfering with others. If you try to use the old read and write permissions in modern versions, you'll be surprised because WRITE_EXTERNAL_STORAGE permission It has become practically obsolete. Now, the system is guided by the type of content: whether it is a photo, a video, or a document, there are specific routes and dedicated APIs to handle them.
Storage locations and their use
To avoid confusion, it's vital to differentiate between the different types of storage the system offers. On one hand, we have the internal storageThis is the most secure and private area. This is where you should store tokens, Room databases, or DataStore preferences, as no one other than your own app can access it.
On the other hand, there is the external storageWithin this, we find shared storage, where the Downloads, Documents, Music, and Pictures folders reside. To interact with these areas without getting bogged down in permissions, Android offers two key tools:
- MediaStore: It's the fastest way to manage media files. If your app creates a photo, you insert it here via the Android MediaProvider module and the system's gallery will recognize it instantly.
- Storage Access Framework (SAF): It's used for non-multimedia files. Through intents like
ACTION_OPEN_DOCUMENTthe user chooses the exact file using the system file explorer and the Storage Access Frameworkgranting timely and secure access.
Critical permissions and the Google Play barrier
Many developers, desperate to regain full access, resort to permissions MANAGE_EXTERNAL_STORAGEThis permission is essentially the "master key" that allows reading and writing to almost all shared storage. However, you must be very careful, as Google Play is extremely strict with its concession.
If your application is not a file manager, antivirus, or backup tool, it is most likely that reject your app If you include this permission without a compelling justification, it's problematic. For the vast majority of cases, such as note-taking apps, social media, or games, the correct approach is to use limited storage and let the user choose via the file selector.
Modern data persistence strategies
It's not all about individual files; data persistence has changed radically. The use of SharedPreferences is no longer recommended because its synchronous writes can block the interface. Instead, Jetpack DataStore It is the winning option, as it works asynchronously using coroutines and Flow, preventing the app from freezing.
For more complex data, the combination of Room and ViewModel It's the current standard. Room acts as an abstraction layer over SQLite, allowing queries to be checked at compile time. Furthermore, by integrating this with a ViewModel, we ensure that data survives screen rotations and that the interface updates reactively.
Differences depending on the Android version
The adaptation is not linear and varies depending on the SDK you're targeting. In Android 9, access was virtually unrestricted. In Android 10, delimited storage was introduced, but an "escape route" was allowed via the flag requestLegacyExternalStorageBut be careful, because in Android 11 that flag stopped working and delimited storage became mandatory.
With Android 13, things have become even more granular. There is no longer a single, general media reading permission; instead, it has been divided into Specific permissions for images, videos, and audioThis allows the user to be much more selective and not give the app access to their entire library if they only need to upload a profile picture.
To navigate the file system during the development phase, tools like ADB or root-accessed explorers are still useful for inspecting the folder /data/data, but remember that the end user experience It will always be limited by SELinux policies and the Android sandbox, ensuring that privacy is the absolute priority in today's mobile ecosystem. Share the information so that other users can learn about the topic.