0

I tried this code

File file = new File("/storage/emulated/0/Movies/Instagram/VID_42790208_180323_463.mp4");
file.delete();

actually its deleted the file. but the content resolver still querying the deleted file path. also i am getting the path from content resolver. help me.

thanks a lot.

4
  • The content resolver does not contain files or file info. What do you mean?
    – blackapps
    Nov 20, 2020 at 19:44
  • But when i query files that gives me the deleted file path ! Nov 20, 2020 at 19:51
  • Your minimal reproducible example should show what you mean by "still exist in content resolver". Nov 20, 2020 at 19:54
  • Still exists i mean that content resolver gives that deleted file path where did the content resolver get the path. Nov 20, 2020 at 20:04

1 Answer 1

2

You have to let the media scanner know that you have deleted the file.

Try the following code after delete.

   MediaScannerConnection.scanFile(mContext, new String[]{file.getPath()}, new String[]{file.getName()},
                    new MediaScannerConnection.OnScanCompletedListener() {
                @Override
                public void onScanCompleted(String s, Uri uri) {
                    getContentResolver().delete(uri, null, null);
                }
            });

Refer the documentation for more info

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.