1

I am using FileProvider to share media to other apps with the following code :

 Intent shareIntentt = new Intent(Intent.ACTION_SEND);
        shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri contentUri = Fileprovider.getUriForFile(context, "com.app.tst", csOrignalFile);
        startActivity(Intent.createChooser(shareIntentt, getResources().getText(R.string.share)));

Here is my provider under <application> tag in manifest :

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.app.tst"
        android:grantUriPermissions="true"
        android:exported="false">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

and this is file_paths.xml :

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
   <external-files-path name="external_files" path="/"/>
</paths>

The File location is

data/user/0/com.app.tst/app_Media/User/2b5b73e511c0f40d07303487b9b43a7c4fe92516/df1c010261115ccba4b6ae484aff79714cb23fd5.jpg

I tried multiple answers from SO and changed path="/" with a couple of variations e.g. FileProvider error "Failed to find configured root that contains /data/data/sawbodeployer.entm.illinois.edu ..." , java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Pictures But every time I am getting the same error.

Process: com.app.tst, PID: 8261 java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.app.tst/app_Media/User/2b5b73e511c0f40d07303487b9b43a7c4fe92516/df1c010261115ccba4b6ae484aff79714cb23fd5.jpg at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:712)

Note: I haven't write any FileProvider of my own.

Syeda Zunaira
  • 5,191
  • 3
  • 38
  • 70

3 Answers3

2

Try

<?xml version="1.0" encoding="utf-8"?>
<paths >
    <external-path
        name="share" path="/"/>

</paths>

instead of external-files-path

Edit:- And you also havent done shareIntent.setData(contentUri); please set the data too.. :)

Santanu Sur
  • 10,997
  • 7
  • 33
  • 52
0

set path="" instead of path="/"

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="external_files" path=""/>
</paths>
sasikumar
  • 12,540
  • 3
  • 28
  • 48
  • And if I run it (ignoring the error) it has still the same issue. – Syeda Zunaira Feb 15 '18 at 07:15
  • your path is vaild? – sasikumar Feb 15 '18 at 07:19
  • this is the path data/user/0/com.app.tst/app_Media/User/2b5b73e511c0f40d07303487b9b43a7c4fe92516/df1c010261115ccba4b6ae484aff79714cb23fd5.jpg and yes it is valid. I am creating new file as 'File csOrignalFile = new File("data/user/0/com.app.tst/app_Media/User/2b5b73e511c0f40d07303487b9b43a7c4fe92516/df1c010261115ccba4b6ae484aff79714cb23fd5.jpg");' – Syeda Zunaira Feb 15 '18 at 07:23
  • refer https://stackoverflow.com/questions/34248855/how-to-set-fileprovider-for-file-in-external-cache-dir/35220426#35220426 – sasikumar Feb 15 '18 at 07:24
0
<external-files-path name="external_files" path="/"/>

Change to

<files-path name="myfiles" path="."/>

And

data/user/0/com.app.tst/app_Media/User/2b5.....

Change to

/data/user/0/com.app.tst/files/app_Media/User/2b5b73e51.....
greenapps
  • 11,154
  • 2
  • 16
  • 19