作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要打开 .pdf 文件。
在 list 中
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
在代码中
file = new File("/storage/emulated/0/Download/ccAlTT_D__.pdf");
Uri uri = Uri.fromFile(file);
Intent intentOpenFile = new Intent(Intent.ACTION_VIEW);
intentOpenFile.setDataAndType(uri, "application/pdf");
intentOpenFile.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentOpenFile);
文件路径正确。它不适用于 android 6,它适用于以下版本。在我单击按钮的那一刻 - pdf 文件打开,但立即关闭。
在日志中
12-23 14:06:53.248 18679-16520/? E/DisplayData: openFd: java.io.FileNotFoundException: Permission denied
12-23 14:06:53.248 18679-16520/? E/PdfLoader: Can't load file (doesn't open) Display Data [PDF : ccAlTT_D__.pdf] +UriOpenable
12-23 14:06:53.381 881-896/? E/KernelCpuSpeedReader: Failed to read cpu-freq: /sys/devices/system/cpu/cpu4/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
我的 list 已满
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="***">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
最佳答案
您不应将文件作为文件 URL 传递给 Intent,因为无法保证(如此处)接收应用程序有权访问该文件。
通过 FileProvider
从文件中传递数据内容提供商网址。
关于android - 如何在android 6上打开pdf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34434342/
我是一名优秀的程序员,十分优秀!