问题
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.
回答1:
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.. :)
回答2:
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>
回答3:
<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.....
来源:https://stackoverflow.com/questions/48801636/file-provider-failed-to-find-configured-root-that-contains