External application is stopped when using FileProvider for opening file from internal storage

强颜欢笑 提交于 2019-12-25 02:55:25

问题


I have some files in custom folder in the internal storage. I need to open the files using external application like Adobe. I planned to open using FileProvider. But the third party application is stopped when trying to open the the document. I really don't know what mistake I did in the code.

package name = "com.example.doc"

activities are in package = "com.example.doc.activities"

manifest

<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>

activity

//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);

Do we need to specify any permission in manifest?

Any help would be appreciated..

Thanks Jomia

来源:https://stackoverflow.com/questions/29384801/external-application-is-stopped-when-using-fileprovider-for-opening-file-from-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!