【问题标题】:Xamarin Android FileProvider Java.Lang.IllegalArgumentException: Failed to find configured root that containsXamarin Android FileProvider Java.Lang.IllegalArgumentException:找不到配置的根目录包含
【发布时间】:2019-11-11 04:38:17
【问题描述】:

我使用 Xamarin 创建 Android 应用程序。我想在其他应用程序中打开我的应用程序文件(比如说 microsoft word 应用程序中的 .docx 文件等)。 我使用 FileProvider,但总是得到这个错误:

Exception:Java.Lang.IllegalArgumentException: Failed to find configured root that contains...

这是我的 FileProvider 文件:

[Android.App.MetaData("android.support.FILE_PROVIDER_PATHS", Resource = "@xml/file_provider_path")]
[Android.Content.ContentProvider(new System.String[] { "${applicationId}.fileProvider" }, Exported = false, GrantUriPermissions = true, Name = "Android.Support.V4.Content.FileProvider")]
public  class AppFileProvider : Android.Support.V4.Content.FileProvider
{
    public AppFileProvider()
    {

    }

}

我还有一个名为 file_provider_path.xml 的 .xml 文件,内容如下:

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

并获取我使用的文件 uri:

Java.IO.File _file = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory, "document1.docx");
AppFileProvider.GetUriForFile(this.ApplicationContext, this.Application.ApplicationContext.PackageName + ".fileProvider", _file)

你能帮我找到解决办法吗?

【问题讨论】:

  • &lt;files-path&gt; 元素指向您应用的内部存储,但该文件位于外部存储中。你想要&lt;external-path&gt;。另请注意,从 Android Q 开始,直接文件系统访问受到严格限制,因此您可能必须更改处理方式。
  • 谢谢@MikeM。解决了我的问题..

标签: android xamarin fileprovider


【解决方案1】:

根据 Mike 的评论,我读到了这个 https://developer.android.com/reference/android/support/v4/content/FileProvider#SpecifyFiles 。 而且我需要在file_provider_path.xml中将“../”设置为我的路径,因为我没有将文件保存在文件夹中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-14
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多