FileProvider:- Setting up file sharing
I know that change the file policy in android nougat.
The wanted app that file share to other apps generate the uri by FileProvider.
The uri format is content://com.example.myapp.fileprovider/myimages/default_image.jpg
.
I want know that how can I get filepath from the uri that generate by FileProvider.getUriForFile()
.
because the my app is need to know the physical filepath in order to save, load, readinfo, etc.
is it possible
[In short]
- My app received the intent uri by other apps on andorid 7 nougat.
- The uri format is
content://com.example.myapp.fileprovider/myimages/default_image.jpg
- Maybe it was generate by
FileProvider.getUriForFile
. - I want to know way that get the file path from uri.
- I can just get the mime type, display name, file size and read binay from
getContentResolver().openFileDescriptor()
. but I wnat to know the filepath.
You cannot get a "file path" for a Uri, for the simple reason that there is no requirement that a Uri point to a file. Use ContentResolver and methods like openInputStream() to access the content represented by the Uri.
I had the similar requirement in our app and got confused earlier. I solved this way.
In Android N, only the file uri exposed to 3rd party app is changed. (Not the way we were using it before).
In our app we were sending uri to Camera app, in that location we are expecting the camera app to store the captured image.
Now we have 2 different uri for same file. #1 is shared with Camera app. If the camera intent is success, we can access the image from #2.
Hope this helps.