java - 由于错误代码,无法使用共享图像按钮:无法找到包含的已配置根
问题描述
我正在创建一个共享图像按钮,但由于某种原因,我收到了这样的错误代码:
java.lang.IllegalArgumentException: Failed to find configured root that contains /document/image:74
at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:744)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
at com.jawad.photoeditor.MainActivity$5.onClick(MainActivity.java:163)
我的清单看起来像:
<provider>
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/fileprovider" />
</provider>
我的fileprovider.xml看起来像:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>
我的具体代码如下:
final Button shareButton = findViewById(R.id.shareButton);
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File file = new File(imageUri.getPath());
Intent intent = new Intent(Intent.ACTION_SEND);
FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()),
BuildConfig.APPLICATION_ID + ".provider", file);
intent.setDataAndType(imageUri, "image/*");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(intent);
}
});
试过这个,但它没有解决问题。任何帮助将不胜感激,在此先感谢!
解决方案
所以我刚刚尝试在我的 xml 文件中添加根路径。
<root-path name="root" path="." />
它现在可以作为一种魅力。问题已解决
推荐阅读
- python - Python 请求:[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:自签名证书
- laravel - 无法在 laravel 中使用其他 Facebook 帐户社交名流登录
- json - 使用 vba 嵌套 json 对象
- jenkins - Grafana:在 OpenShift 上自动部署仪表板
- r - R:重新思考数据(如何重新排列一组列中的一列?)
- kubernetes - AWS AppMesh VirtualService 名称与 AWS EKS 中的服务名称的区别
- woocommerce - 批量订单状态(woocommerce)的钩子是什么?
- phoenix-framework - Phoenix 服务器不使用 Docker 渲染 css 和图像
- ssl - Wildfly 与 java 11 启动错误 javax.net.ssl
- java - Java SecurityException:签名文件摘要无效