1

The uri is as follows:

content://com.google.android.apps.photos.contentprovider/-1/1/file%3A%2F%2F%2Fstorage%2Femulated%2F0%2FDCIM%2Fimg1.jpg/ORIGINAL/NONE/1347105467

Getting path return the below data as follows:

/-1/1/file:///storage/emulated/0/DCIM/img1.jpg/ORIGINAL/NONE/1347105467

I am also getting null while going to read input stream using the below code.

InputStream inputStream = getContentResolver().openInputStream(uri);
  • 1
    See also [this](https://stackoverflow.com/questions/48510584/onactivityresults-intent-getpath-doesnt-give-me-the-correct-filename) and [this](https://stackoverflow.com/questions/49221312/android-get-real-path-of-a-txt-file-selected-from-the-file-explorer) and [this](https://commonsware.com/blog/2016/03/15/how-consume-content-uri.html). – CommonsWare Apr 06 '18 at 11:17
  • I have the uri only. I have to fetch exact path of that file. – Kaushik Chatterjee Apr 06 '18 at 11:21
  • A `Uri` does not always point to a file, let alone one that you can read. Please read [my answer](https://stackoverflow.com/a/35870955/115145) on the duplicate question. – CommonsWare Apr 06 '18 at 11:25
  • here getScheme() returns content. using DocumentFile.fromSingleUri() how do I get file path? – Kaushik Chatterjee Apr 06 '18 at 11:30
  • You don't. The `Uri` does not always point to a file, and even if it does, you have no reliable way of determining where that file is. So, please follow the instructions in the answers on the duplicate question. Or, if you got that `Uri` via something like `ACTION_GET_CONTENT`, switch to [a file picker library](https://android-arsenal.com/tag/35), if all you can handle are files. – CommonsWare Apr 06 '18 at 11:32
  • I got the uri while another app like google photos want to share file to our app. I am trying to get input stream but getting null. – Kaushik Chatterjee Apr 06 '18 at 11:37
  • I do not know why you would get `null` from `openInputStream()` for a `Uri` that you received via `ACTION_SEND` (which is my guess as to "want to share file to our app" means). You might consider asking a separate Stack Overflow question, where you provide a [mcve]: the code that is getting this `Uri`, the code that is calling `openInputStream()`, and the stack trace from your crash. – CommonsWare Apr 06 '18 at 11:42
  • java.io.FileNotFoundException: File not found: null, at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151) – Kaushik Chatterjee Apr 06 '18 at 11:54
  • got the above error while want to get input stream from above api. – Kaushik Chatterjee Apr 06 '18 at 11:55
  • You might consider asking a separate Stack Overflow question, where you provide a [mcve] example: the code that is getting this `Uri`, the code that is calling `openInputStream()`, and the complete Java stack trace from your crash. – CommonsWare Apr 06 '18 at 12:04
  • You can see that the wanted path is contained in the url you posted: `file%3A%2F%2F%2Fstorage%2Femulated%2F0%2FDCIM%2Fimg1.jpg`. So that is `file:///storage/emulated/0/DCIM/img1.jpg` or `/storage/emulated/0/DCIM/img1.jpg` So easy to parse it out. – greenapps Apr 06 '18 at 12:45

0 Answers0