Skip to content

Instantly share code, notes, and snippets.

@fercarcedo
Last active November 28, 2021 09:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fercarcedo/fc1a2452d47a61a6bfdb759ed6e62ffa to your computer and use it in GitHub Desktop.
Save fercarcedo/fc1a2452d47a61a6bfdb759ed6e62ffa to your computer and use it in GitHub Desktop.
Delete images Scoped Storage
private fun deleteImages(uris: List<Uri>) {
val pendingIntent = MediaStore.createDeleteRequest(contentResolver, uris.filter {
checkUriPermission(it, Binder.getCallingPid(), Binder.getCallingUid(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != PackageManager.PERMISSION_GRANTED
})
startIntentSenderForResult(pendingIntent.intentSender, REQ_CODE, null, 0, 0, 0)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQ_CODE && resultCode == Activity.RESULT_OK) {
// Image deleted successfully
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment