IllegalArgumentException:无法找到包含在FileProvider.getUriForFile上的配置根目录

时间:2019-04-02 11:05:12

标签: android android-webview

我正在尝试从远程位置共享文件,但是出现以下异常:

java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/31AB-1310/Android/data/com.example.myapp/cache/EasyImage/a9c926ea-4dce-44b7-94e9-a5dca6b91a5d-450242437.jpg
    at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
    at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
    at pl.aprilapps.easyphotopicker.EasyImage.createCameraPictureFile(EasyImage.java:54)
    at pl.aprilapps.easyphotopicker.EasyImage.createChooserIntent(EasyImage.java:109)

我的FileProvider代码具有以下清单条目:

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
         android:name="android.support.FILE_PROVIDER_PATHS"
         android:resource="@xml/file_provider_paths" />
</provider>

我的res / xml / filpaths.xml文件:

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

我的Activity.java文件:

private void shareCurrentData(String filepath) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("*/*");
    ArrayList<Uri> files = new ArrayList<Uri>();
    if (intent.resolveActivity(getPackageManager()) != null) {
        try {
            File shareFile= new File(filepath);
            Uri shareUri =FileProvider.getUriForFile(this, AUTHORITY,shareFile);
            //files.add(textUri);
            files.add(shareUri);
        } catch (Exception ex) {
            System.out.println(ex);
        }
        intent.putExtra(Intent.EXTRA_STREAM, files);
        startActivity(Intent.createChooser(intent,"Share using....."));
    }
}

我只是不明白是什么引起异常,因为一切似乎都合适。

1 个答案:

答案 0 :(得分:0)

if($('#reference_sites').length){
$output = "<textarea id='ckeditor-rs' name='ckeditor-rs' rows='10' cols='80'></textarea>";
$('#reference_sites').append($output);
CKEDITOR.replace('ckeditor-rs');

var editor = CKEDITOR.instances['ckeditor-rs'];
editor.setData("{{$proposal->reference_sites}}");

}else{
    console.log("couldn't append ckeditor in rs");
}

类似的路径通常来自可移动存储。 /storage/31AB-1310/Android/data/com.example.myapp/cache/EasyImage/a9c926ea-4dce-44b7-94e9-a5dca6b91a5d-450242437.jpg 不支持可移动存储。

因此,请专注于确保FileProvider位于external storage而非removable storage上。