android - IllegalArgumentException:未能找到包含在 FileProvider.getUriForFile 上的配置根
问题描述
我正在尝试从远程位置共享文件,但出现以下异常:
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....."));
}
}
我只是不明白是什么引发了异常,因为一切似乎都合适。
解决方案
推荐阅读
- ruby-on-rails - 远程服务的模拟登录 - Cucumber、Capybara、Rails
- ruby-on-rails - 将 ruby 从 2.3.1 升级到 3.0.1 后出现 Rails Paperclip 错误
- arduino - ESP32 如何使用 http.addHeader() 添加主机标头
- kubernetes - 具有 dnsmasq 问题的 Kubernetes HostPort
- python - python中column -t命令的替代品?
- aws-lambda - 使用 boto3 client.start_workflow_run() 时,lambda 在所有工作流程处理时间内运行?
- docker - 使用 docker 在 keycloak 上启用细粒度
- javascript - forEach 方法在迭代时跳过对象
- javascript - 如何在 d3 日历热图中显示像 github 热图这样的日期?
- reactjs - 在 react-native 组件中导入颜色样式不起作用