0

I'm here speaking in context of USB not a Memory card or Internel memory and need a exact path not a Uri.

Till Android L i get a File path from a /mnt or /storage or any other directory.but in marshmallow i didn't find where my usb is exactly.

then i move forward towards the Storage Access Framework.but it's not returning the actual path it's return me a Uri.

I also go through the AFileChooser Project and A stackoverflow post Android Gallery on KitKat returns different Uri for Intent.ACTION_GET_CONTENT

but It's not helpfull.So is there any way i can access the Realpath like (/storage/abc/filename.mp4).

Community
  • 1
  • 1
wVV
  • 63
  • 1
  • 10

1 Answers1

1

then i move forward towards the Storage Access Framework.but it's not returning the actual path it's return me a Uri.

That is because the Storage Access Framework does not work with files. It works with storage providers. Storage providers are welcome to store their pieces of content however their developers want. That can include content stored on servers, content stored in databases, content stored in encrypted containers, content generated on the fly, and so on. None of those have an "actual path" that is meaningful to you. And, if you are using the Storage Access Framework, the user can choose whatever storage provider that the user wants.

So is there any way i can access the Realpath like (/storage/abc/filename.mp4).

Make your own copy of the content, using the Uri and Java I/O. Then you know the "Realpath" of your copy.

A Uri is like a URL. There is no requirement for the URL of this Web page to map to some file on your computer. There is no magic algorithm that will convert a URL to a local file path... other than to download the content yourself and create a local file.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • elaborate own copy of the content.how i can make a copy of video file.any link? – wVV Aug 18 '16 at 13:04
  • @wVV: Use `ContentResolver` and `openInputStream()` to get an `InputStream` on the content identified by the `Uri`. Create a `FileOutputStream` on a local file (e.g., `getCacheDir()`). Use Java I/O to copy the bytes from the `InputStream` to the `OutputStream`. There are other implementations, but that's the typical approach and an example of the pattern. – CommonsWare Aug 18 '16 at 13:06
  • what about if file size is greater than 250mb.it will create a overhead on system. – wVV Aug 18 '16 at 13:17
  • @wVV: Yes. This is why it is better to just use the `Uri` directly and not make a copy. The only reason to make a copy is if you have to use some C/C++ code to manipulate the content, and even then there's a chance that you can go the `AssetFileDescriptor` route, to get a file descriptor to the native code that it can use. If all your code is in Java, there should be no reason that you need a file. – CommonsWare Aug 18 '16 at 13:27
  • Tnx man your approach is working.and one more thing you told me about other implementation in comment what it is? – wVV Aug 18 '16 at 14:39
  • @wVV: `ContentResolver` also has `openFileDescriptor()` and `openAssetFileDescriptor()` methods. [A "file descriptor" is a POSIX thing](https://en.wikipedia.org/wiki/File_descriptor), which C/C++ on Linux/Android can work with. It is possible that you could use those methods to get a file descriptor that you could pass to native code for processing the content. However, I have not even researched this, let alone tried it. – CommonsWare Aug 18 '16 at 14:44
  • @commanware what if didn't want a System Picker or is there any way we can disable the system picker and get a ListOfFiles in a list without displaying the system picker. – wVV Aug 19 '16 at 11:11
  • @wVV: Not for arbitrary locations on removable media. – CommonsWare Aug 19 '16 at 12:39