5

Am trying to support Nougat by getting rid of FileUriExposedException.When I use Uri.fromFile(gettheImageFilehere()) method I successfully get the image 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 have tried to use the implemetation provided on android.os.FileUriExposedException Here is my code in my androidmanifest.xml inside I added the 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>

I then created the provider_paths.xml in res/xml folder as 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:

  1. In some example I found that they use the full path. i.e Android/data/com.example.com/files.I don't know if its the same as just having the path as a. Hopefully someone can clear that up for me.

The full error am getting is Unable to decode stream: java.io.FileNotFoundException: /external_files/DCIM/Camera/IMG_20170308_175833.jpg (No such file or directory)

The code snippet .java file is here to view my implementation.

Community
  • 1
  • 1
GotaloveCode
  • 994
  • 1
  • 13
  • 30

1 Answers1

0

Try using Intent iGallery = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);