使用FileProvider从内部存储打开文件时,外部应用程序停止

时间:2015-04-01 07:04:50

标签: android android-fileprovider

我在内部存储中的自定义文件夹中有一些文件。我需要使用像Adobe这样的外部应用程序打开文件。我计划使用FileProvider打开。但是在尝试打开文档时,第三方应用程序停止了。我真的不知道我在代码中犯了什么错误。

包名=" com.example.doc"

活动在package =" com.example.doc.activities"

清单

<provider
     android:name="android.support.v4.content.FileProvider"
     android:authorities="com.example.doc.fileprovider"
     android:exported="false"
     android:grantUriPermissions="true" 
     android:readPermission="com.example.doc.fileprovider.READ">
     <meta-data
         android:name="android.support.FILE_PROVIDER_PATHS"
         android:resource="@xml/filepath" />
  </provider>

RES / XML / filepath.xml

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

活性

//tempfilePath = /data/data/com.example.doc/files/RBC/sample.docx

File file = new File(tempfilePath);         
Uri exportUri = FileProvider.getUriForFile (this, "com.example.doc.fileprovider", file);

Intent docViewIntent = new Intent();
docViewIntent.setAction(Intent.ACTION_VIEW);
docViewIntent.setDataAndType(exportUri , extensionType);
docViewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
docViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(docViewIntent);

我们是否需要在清单中指定任何权限?

任何帮助将不胜感激..

由于 Jomia

0 个答案:

没有答案
相关问题