How to delete a video recorded using an Intent wit

2019-07-11 21:04发布

I would like to remove a video that has been previously recorded using an Intent:

Intent captureVideoIntent = new Intent(
                  android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(captureVideoIntent, VIDEO_CAPTURED);

The method onActivityResult() get the recorded video as Intent data. I try to obtain the recorded file and delete it.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Code for modify and copy the video
    try {
            Uri androidUri = data.getData();
            File file = new File(new java.net.URI(androidUri.toString()));
            file.delete();
    } catch (Exception e) {
            e.printStackTrace();
    }
}

But I get the error:

java.lang.IllegalArgumentException: Expected file scheme in URI: content://media/external/video/media/177.

Does somebody know how can I get the path of the recorded video and move or delete it?

1条回答
姐就是有狂的资本
2楼-- · 2019-07-11 21:30

This answer has how to get the path from a content URI. You should be able to pass its result to the File constructor.

查看更多
登录 后发表回答