我尝试打开pdf文件。
AndroidManifest.xml
<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
<?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" />
打开文件方法
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);
而且我总是会捕捉到此异常
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /Download/Киоски.pdf
我找不到足够的解释是什么问题。
对不起,我的英语不好(((((
谢谢。
答案 0 :(得分:0)
我将file_path.xml更改为:
<?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>
然后尝试:
Uri contentUri = getUriForFile(getContext(), "com.interactivegroup.android.fileprovider", newFile);