gpt4 book ai didi

android - 如何在android 6上打开pdf文件

转载 作者:行者123 更新时间:2023-11-29 01:25:20 24 4
gpt4 key购买 nike

我需要打开 .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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com