首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FileProvider IllegalArgumentException

FileProvider IllegalArgumentException
EN

Stack Overflow用户
提问于 2018-09-10 22:02:57
回答 1查看 47关注 0票数 0

我尝试打开pdf文件。

AndroidManifest.xml

代码语言:javascript
复制
<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.interactivegroup.android.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />

    </provider>

我在Android设备上的下载文件夹中的pdf文件

file_paths.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?><paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="files" path="." />
<root-path name="pdfs" path="/storage/emulated/0/Download" />

打开文件方法

代码语言:javascript
复制
File file = new File(Environment.DIRECTORY_DOWNLOADS+"/Киоски.pdf");

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    Uri uri = FileProvider.getUriForFile(SendActivity.this,  "com.interactivegroup.android.fileprovider", file);
    intent.setDataAndType(uri, "application/pdf");
    SendActivity.this.getApplicationContext().startActivity(intent);

我总是捕捉到这个异常

代码语言:javascript
复制
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /Download/Киоски.pdf

我找不到足够的解释出了什么问题。

对不起,我的英语不好(

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-09-10 22:36:31

我会将file_path.xml更改为:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
  <paths xmlns:android="http://schemas.android.com/apk/res/android">
      <external-path name="files" path="."/>
      <external-path name="pdfs" path="Download/" />
  </paths>

并尝试:

代码语言:javascript
复制
Uri contentUri = getUriForFile(getContext(), "com.interactivegroup.android.fileprovider", newFile);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52259544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档