0

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

Community
  • 1
  • 1
idan
  • 1,508
  • 5
  • 29
  • 60
  • You can use [ Uri.parse(fileName)](http://developer.android.com/reference/android/net/Uri.html#parse%28java.lang.String%29) – Arun C May 08 '13 at 12:07

2 Answers2

3

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())
DroidBender
  • 7,762
  • 4
  • 28
  • 37
  • 1
    i recive file:///mnt/sdcard/Movies/Your_voice/Your_voice080513_141510.mp4 not this format content://media/external/video/media/2308 – idan May 08 '13 at 12:11
0

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

Community
  • 1
  • 1
rcbevans
  • 7,101
  • 4
  • 30
  • 46
  • i try this but i dont know why not work Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File("/mnt/sdcard/Movies/Your_voice/Your_voice080513_141510.mp4"); intent.setDataAndType(Uri.fromFile(file), "video/*"); //startActivity(intent); startActivityForResult(intent, RESULT_PICK_IMAGE_CROP); – idan May 08 '13 at 12:27
  • What is RESULT_PICK_IMAGE_CROP? is that a mask you have set yourself? I haven't heard of it – rcbevans May 08 '13 at 12:30
  • it just final int like 4 , in the result i have switch. in the result FileURI = data.getData(); – idan May 08 '13 at 12:47
  • Are you sure the application you are trying to launch with will return a result? What errors are you getting. It is hard to be helpful without things like Logcats to see what is actually happening. It could be a number of things. Is there definitely an MP4 compatible video player. Does the video file definitely exist? Also, what are you trying to do with this video having named the flag RESULT_PICK_IMAGE_CROP – rcbevans May 08 '13 at 12:54
  • Have updated my answer on how to get a content Uri from a file – rcbevans May 08 '13 at 13:45
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29601/discussion-between-o0rebelious0o-and-idan) – rcbevans May 08 '13 at 13:45