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

)

Final result

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.