Removing a file from contentResolver only removes the record from the database (not the file)

I am trying to delete a file using contentResolver, but only delete the record from the database, not the real file. So I will try to delete the record first and then 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 doesn't ContentResolver delete the real file? This is normal?

+4
source share
2 answers

It works:

  // 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 doesn't contentResolver delete the file?

+1
source

It appears that in 4.2 it nullifies the file but does not delete it. I really hoped that he would just delete it from the MediaStore and not delete it from the file system. In any case, this seems to be an Android bug.

I am having a problem updating the file. The problem that I am facing is that the media scanner does not delete the old record when rescanning, so you get two records.

0
source

All Articles