Android Device Storage Mechanisms
Android provides multiple storage options for apps to save data, differing in visibility, accessibility, lifetime, and storage location. The main storage mechanisms include internal storage, external storage, and app-specific storage, with significant changes introduced in Android 10 through Scoped Storage, which is a new security model that governs access to shared external storage (including SD cards) with restricted permissions and APIs.
Internal Storage
Internal storage is private space for your app on the device's built-in memory. Other apps can't access it. Includes:
- Files: Your app's private file storage (documents, images, etc.)
- Cache: Temporary files that Android may delete when space is needed
- Databases: For organized, searchable data (SQLite/Room)
- SharedPreferences: Simple storage for:
- App settings and preferences
- Small amounts of simple data (flags, IDs, etc.)
- Can cause app slowdowns if used too much
- DataStore: Better version of SharedPreferences that:
- Runs smoothly without slowing your app
- Can store more complex data
- Automatically handles errors
- Better for frequently changing data
External (Shared) Storage
This is storage accessible to both users and apps, traditionally located on the SD card or partitioned external memory. It includes:
- Public Directories: e.g., Downloads, Pictures, Music, etc., where user files are stored.
- App-specific External Storage: Stored in
/Android/data/<package_name>/, accessible only by the app. - Scoped Storage: From Android 10+, apps must access files using permission-based APIs that restrict access to only their own files or media types.
App-specific Storage
Apps have dedicated storage on both internal and external storage:
- Internal: Stored in the app’s sandbox and deleted on uninstall.
- External: Located under
/Android/data/<package_name>/, removed when the app is uninstalled.
Scoped Storage (Android 10+)
Scoped Storage limits access to shared storage, improving user data privacy. Apps can only:
- Access their own files freely.
- Access media files using MediaStore APIs (images, audio, video).
- Request permissions (like MANAGE_EXTERNAL_STORAGE) for broader access, but this is discouraged.
MediaStore Access
Under scoped storage, apps access media (images, audio, video) via MediaStore API. It allows safe interaction with shared files without needing direct file paths. Files are indexed and can be queried by content resolver.
Legacy Access (Pre-Android 10)
Earlier versions of Android allowed direct access to any file on shared storage with just READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE permissions. This model was less secure and deprecated in favor of Scoped Storage.
Summary
- Internal Storage: Private to app; includes files, preferences, DBs, and cache.
- External Storage: Shared with user and other apps (with limitations from Android 10+).
- Scoped Storage: Modern access control for shared files.
- MediaStore: Scoped API to interact with multimedia.
- Cache: Temporary files, cleared when space is low or app is uninstalled.