I try to delete a file using contentResolver but only delete the entry from database, not the real file. So I try delete first the entry and later the file:
int rows = context.getContentResolver().delete(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
MediaStore.Audio.Media._ID + "=" + idSong, null);
// Remove file from card
if (rows != 0) {
Uri uri = ContentUris.withAppendedId(
        MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, idSong);
File f = new File(uri.getPath());
if(!f.delete())
    Log.d("fail-2", "fail-2");  
}
else
Log.d("fail-1", "fail-1");
...and the output is "fail-2". Why?
Why ContentResolver doesn't delete the real file? Is this normal?
This is working:
    // Remove entry from database
    int rows = context.getContentResolver().delete(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            MediaStore.Audio.Media._ID + "=" + idSong, null);
    // Remove file from card
    if (rows != 0) {
        try {
            File f = new File(path);
            if (f.delete())
                return true;
        } catch (Exception e) {
            Log.d("MusicDB", "file: '" + path
                    + "' couldn't be deleted", e);
            return false;
        }
    }
    return false;
But why contentResolver doesn't delete the file??
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With