0

I am using Native Camera intent to capture video. In Nexus S If i capture a video then whether i cancel or pressed ok always the video file is getting store in default Medi URI path. But I have a requirement to delete the captured video when user clicks ok. I am using following code to call camera

Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(videoIntent, CAPTURE_VIDEO);

and following ciode handles cancel button click event

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            if (requestCode == CAPTURE_VIDEO) {if(resultCode == Activity.RESULT_CANCELED) 
//pointer comes here successfully. It tells that cancel button is clicked. But I am unabelt to know how to delete the currently cancelled video
}
}
}
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243

1 Answers1

0

Ok, Its some ugly way..

First get the real path of the video from returned URI, like

private String videoPath = "";

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAPTURE_VIDEO) 
    {

      Uri vid = data.getData();
      videoPath = getRealPathFromURI(vid);
    }   
}

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Videos.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Videos.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

Now you have a real path of video file then using file operation you can delete it.

File videoFile = new File(videoPath);
videoFile.deleteOnExit();

I doubt if there is available any method to delete it form android database..

user370305
  • 108,599
  • 23
  • 164
  • 151