0

I am trying to delete a video file located at the path

/storage/6638-3139/DCIM/Camera/20180503_144303.mp4

I have done below code for that.

delete(getContext(),file);

public static boolean delete(final Context context, final File file) 

{

final String where = MediaStore.MediaColumns.DATA + "=?";

    final String[] selectionArgs = new String[] {
            file.getAbsolutePath()
    };
    final ContentResolver contentResolver = context.getContentResolver();
    final Uri filesUri = MediaStore.Files.getContentUri("external");

    contentResolver.delete(filesUri, where, selectionArgs);

    if (file.exists()) {

        contentResolver.delete(filesUri, where, selectionArgs);
    }
    return !file.exists();
}

When i am using above code then the video i couldn't see them in my gallery but when i am exploring my file manager its exist.

file.delete()- This method is also not working.

I am using the same path.

When i am saving this video file in internal memory and then trying to delete from there then that time its working fine but in case of sd card its not working.

Please help.

Nikunj
  • 3,937
  • 19
  • 33
  • Deleting rows from the `MediaStore` does not delete the underlying content. You do not have the ability to work with arbitrary filesystem paths on removable storage. – CommonsWare May 03 '18 at 10:22
  • @CommonsWare Can u give me some suggestion to delete those videos . – user1960700 May 03 '18 at 10:31
  • AFAIK, there is no reliable solution for this. If you are the one putting the videos on removable storage, put them in a place that *you can work with reliably*: locations returned by `getExternalFilesDirs()`, `getExternalCacheDirs()`, or `getExternalMediaDirs()`. Or, stop worrying about external storage/removable storage and switch to the Storage Access Framework (`ACTION_CREATE_DOCUMENT`, etc.), so the user can decide where to place the video and you can have long-term access to the content. – CommonsWare May 03 '18 at 10:33

0 Answers0