0

I am trying to delete a video file from the gallery but the below code is not working properly.
It deletes only the content, but the video remains in the gallery and when I try to play the video it says that the video cannot be played.

public void deleteVideo(View view)
{
    File f = new File(delete);
    f.delete();
    if(f.exists())
    {
        try
        {
            Toast.makeText(
                TestVideoRecordingActivity.this,
                "inside try",
                Toast.LENGTH_SHORT
            ).show();
            f.getCanonicalFile().delete();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            dialog.dismiss();
        }
    }
    dialog.dismiss();
}
Mann
  • 560
  • 3
  • 13
Nandini
  • 21
  • 1
  • 2
  • 1
    Possible duplicate of [android : deleting an image](http://stackoverflow.com/questions/10716642/android-deleting-an-image) – Dhaval Parmar Feb 05 '16 at 10:21

1 Answers1

0

Just add below line after you programatically delete the video file -

For api < 14

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + 
Environment.getExternalStorageDirectory())));

for api >= 14

MediaScannerConnection.scanFile(MainActivity.this, 
new String[] { Environment.getExternalStorageDirectory().toString() }, 
null, 
new MediaScannerConnection.OnScanCompletedListener() {

    public void onScanCompleted(String path, Uri uri) {

              Log.i("ExternalStorage", "Scanned " + path + ":");
              Log.i("ExternalStorage", "-> uri=" + uri);
    }
});
kevz
  • 2,727
  • 14
  • 39