Anyone familiar with the new scoped storage rules?...
# android
Anyone familiar with the new scoped storage rules? I’m attempting to delete a file like so:
Copy code
context.contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, "${MediaStore.Audio.Media._ID} = ?", arrayOf(id.toString()))
Supposedly, if I don’t have permission, this should throw a
on Android Q, and I should be able to use an IntentSender to have the user grant permission. Instead, I just get a result of
from the
call, meaning no files were deleted. Any ideas?
I have had the exact same problem a few months ago. This only works if you specify the full Uri of the Media you'd like to delete, the one obtainable with
ContentUris.withAppendedId(Media.EXTERNAL_CONTENT_URI, longId)
. For more information see my question an its excellent answer on SO:
Thanks 🙂 I did come across this answer. I didn’t understand what
was for a while, but I did get it wokring. Turns out the underlying file isn’t deleted even when contentResolver.delete() returns >= 1
Looks like Scoped Storage feature isn't really ready on Android Q ... I recommend sticking with
until at least Android 11 (but that flag is still allowed on Android 11 !)