New MediaStore Trash API in Android R
Along with many restrictions new android R brings some new useful APIs. One of them is a new Trash API:
MediaStore#createTrashRequest(ContentResolver, Collection<Uri>, boolean)
The method returns an instance of PendingIntent which should be used to prompt the user to move selected files to the trash using:
startIntentSenderForResult(
intentSender,
DELETE_PERMISSION_REQUEST,
null,
0,
0,
0,
null
)In order to demonstrate this API in action I’ve forked MediaStore sample app and replaced permanent removing by moving to the trash.
The main difference is located in view model:
In order to determine whether the media file is in the trash or not a new column MediaColumns#IS_TRASHED is added.
Also MediaStore#QUERY_ARG_MATCH_TRASHED should help to filter files from the trash.
LinkedIn: https://www.linkedin.com/in/ymysochenko/
Twitter: https://twitter.com/sdexyz
