Question

I've tried using content resolver's delete method to delete an image file. It shows that it has been deleted but I don't see any difference when I check in the image folder.

    int id =  getLastImageId();
    int deleted = getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,    
    MediaStore.Images.Media._ID + "=?", new String[]{ Long.toString(id) } );
    Log.i("", "total deleted rows:" + deleted);

In the logcat, I can see that total deleted rows is 1. You can be rest assured that the getLastImageId method is correct. Besides I've even tried to delete everything in the MediaStore table but to no avail. For example:

    int id =  getLastImageId();
    int deleted = getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,    
    null, null);
    Log.i("", "total deleted rows:" + deleted);

For this example, the total rows deleted is 834, which is everything in my phone but still the images persists. FYI, the images I'm checking is at sdcard/DCIM/Camera

Hope to get some help from you.

Regards, Dexter

Was it helpful?

Solution

I think that your code is only deleting the data from the tables MediaStore.Images.Media tables and not the physical images.

What you can is query the MediaStore.Images.Media.DATA field which gives you the absolute path to the image.

Then delete the file as you would delete a normal file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top