idan
idan

Reputation: 2200

convert url from sdcard to content uri

i want to bypass Intent.ACTION_PICK to do so i need to insert content uri but i have string with url.

i need to convert this format :

 /mnt/sdcard/Movies/Your_voice/Your_voice080513_141510.mp4

to uri format :

content://media/external/video/media/2308

i find this :

How to convert a file:// uri into content:// uri?

and this to image Convert file uri to content uri

update :

I have a method that send file, this method gets content uri.

so to use this method i'm using intent because the output is content uri.

i'm using this intent :

Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("video/*");
        startActivityForResult(intent, RESULT_PICK_IMAGE_CROP);

this intent open folder, the user pick folder and after video file

my previous Q : intent ACTION_PICK in specific folder

the problem is that i need just specific folder , but i red here

Using Intent.ACTION_PICK for specific path

this is not possible.

so i try to convert The path that I have to content url

Upvotes: 0

Views: 2602

Answers (2)

rcbevans
rcbevans

Reputation: 8921

You can use

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("%PATH_TO_FILE%/test.mp4");
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);

That will open the file with the default video player bypassing the choice

You can get a content URI from a file like this

Uri myUri = Uri.fromFile(new File("/sdcard/cats.jpg"));

or like this

Uri myUri = Uri.parse(new File("/sdcard/cats.jpg").toString());

That should give you a Uri you can use

Reference: Get content uri from file path in android

Upvotes: 0

DroidBender
DroidBender

Reputation: 7902

Snippet:

Uri.fromFile(new File("/mnt/sdcard/Movies/Your_voice/Your_voice080513_141510.mp4"))

or

Uri.parse(new File("/mnt/sdcard/Movies/Your_voice/Your_voice080513_141510.mp4").toString())

Upvotes: 3

Related Questions