I am trying to support Nougat by getting rid of FileUriExposedException. When I use the Uri.fromFile(gettheImageFilehere()) method, I successfully get the file path file: ///storage/emulated/0/DCIM/Camera/IMG_20170308_171951.jpg When I use
FileProvider.getUriForFile(HomeView.this, getApplicationContext().getPackageName() + ".provider", gettheImageFilehere());
I get the image path as: /external_files/DCIM/Camera/IMG_20170308_171951.jpg
I tried using the implementation presented in android.os.FileUriExposedException Here is my code in my androidmanifest.xml inside I added a provider:
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider>
Then I created provider_paths.xml in the res / xml folder, as shown below:
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="external_files" path="."/> </paths>
My doubts about the above:
- In some example, I found that they use the full path. ie Android / data / com.example.com / files . I do not know if this coincides with that which has only a path. Hope someone can clear this.
Full error am getting is Unable to decode stream: java.io.FileNotFoundException: /external_files/DCIM/Camera/IMG_20170308_175833.jpg (There is no such file or directory)
The .java code snippet file is here to view my implementation.
source share