Android 11 has a hidden Recycle Bin for trashed photos and videos
Google is attempting to rein in the out-of-control app storage situation with “Scoped Storage.” Scoped Storage was introduced in Android 10 but has since been changed several times since its debut because of how dramatically it affects storage access for many Android applications. Google is enforcing Scoped Storage for apps that target API level 30, which is the latest API level coinciding with Android 11.
Rather than try to explain Scoped Storage all over again, here’s a graphic from Google’s “All things privacy in Android 11” talk that summarizes how Scoped Storage will affect storage access for apps in Android 11.
One of the more interesting changes to storage access that has flown under the radar thus far is the introduction of a new “trashing” mechanism. This feature is detailed in Google’s “Storage access with Android 11” video. In essence, apps using the MediaStore API can trash a file instead of deleting it in order to give the user a chance to recover the file later. Google likens this feature to the Recycle Bin on PCs except Android’s recycle bin is hidden by default. Google states that apps with edit access to trashed files or that request user consent can display items from the recycle bin, though. Items that are trashed are automatically deleted by Android after 30 days.
Android 11 is also requiring that apps get consent from a user before modifying media files that the app doesn’t own. Another new feature that has been added is “favorites,” which allows media apps to add a “favorite” file status to designated media items so that other media apps will know that the user views these items as important. For instance, if the user stars an item in a gallery app, then other media apps can see that this item has been favorited.
Although Google’s talk doesn’t show an example of the MediaStore’s new trash concept, the API has been available since the first Android 11 Developer Preview. Developer Yuriy Mysochenko published an article on Medium back in February that goes over this new API, and he demonstrated the API in a sample app as shown below:
In this demo, the app asked the user if they wanted to move a photo to trash which would temporarily delete the photo from the gallery. After 7 days, the photo would be permanently deleted from storage. Googler Roxanna Aliabadi mentions that the OS stores trashed items for 30 days, so the 7-day storage limit was likely increased since the first Developer Preview.
Developers interested in implementing this API can check out the documentation right now on the Android Developers website. Media apps can create a PendingIntent called createTrashRequest to prompt the user to trash an item, which then adds the flag IS_TRASHED indicating that a media item has been trashed. Trashed items are retained by the OS until DATE_EXPIRES, after which they are permanently deleted from storage. Media apps querying the MediaStore must explicitly query for trashed items using QUERY_ARG_MATCH_TRASHED as trashed items are filtered away from operations by default.
You can (and should) listen to this full talk on Scoped Storage if your app deals with storage access: