2

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jgilrincon
  • 124
  • 1
  • 8
  • Have you tried just passing the `URI` to the `File` constructor? Example...`File file = new File(uri);` – Squonk Jun 28 '11 at 23:07
  • Yes, but the File constructor needs an URI not an Uri. I should convert the android.net.Uri to an java.net.URI. This question is unresolved in http://stackoverflow.com/questions/559902/android-how-can-i-convert-android-net-uri-object-to-java-net-uri-object. – jgilrincon Jun 29 '11 at 13:33
  • If I try: File file = new File(new java.net.URI(androidUri.toString())); I get the error: java.lang.IllegalArgumentException: Expected file scheme in URI: content://media/external/video/media/177 . Thanks – jgilrincon Jun 29 '11 at 14:20

1 Answers1

4

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

Community
  • 1
  • 1
Jess
  • 42,368
  • 6
  • 37
  • 51