有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法使用共享映像按钮,因为错误代码:未能找到包含

我正在创建一个共享图像按钮,但由于某种原因,我得到了这样一个错误代码:

java.lang.IllegalArgumentException: Failed to find configured root that contains /document/image:74
        at 安卓x.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:744)
        at 安卓x.core.content.FileProvider.getUriForFile(FileProvider.java:418)
        at com.jawad.photoeditor.MainActivity$5.onClick(MainActivity.java:163)

我的清单看起来像:

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

还有我的文件提供者。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);
            }
        });

尝试过这个,但没有解决问题。任何帮助都将不胜感激,提前感谢


共 (1) 个答案

  1. # 1 楼答案

    所以我刚刚尝试在xml文件中添加一个根路径

    <root-path name="root" path="." /> 
    

    现在,它是一种魅力。问题解决了