我尝试打开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我找不到足够的解释出了什么问题。
对不起,我的英语不好(
谢谢。
发布于 2018-09-10 22:36:31
我会将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);https://stackoverflow.com/questions/52259544
复制相似问题