【发布时间】:2021-03-07 11:58:03
【问题描述】:
我正在使用外部 pdf 查看器应用程序打开 pdf 文件。但在 android 11 中显示 eacces 权限被拒绝问题。我的清单文件中已经声明了所有权限。
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
还声明了这一点:
android:requestLegacyExternalStorage="true"
使用以下代码创建和编写内容:
byte [] decodedContent = Base64.decode(base64.getBytes(), Base64.DEFAULT);
try {
File pdfDirPath = new File(getApplicationContext().getExternalFilesDir(null).getAbsolutePath(), "pdfs");
File file5 = new File(pdfDirPath, globalData.getVin()+".pdf");
if (!file5.exists()) {
file5.getParentFile().mkdirs();
}
outputStream = new FileOutputStream(file5);
outputStream.write(Base64.decode(base64, Base64.NO_WRAP));
outputStream.close();
然后像这样打开上面的文件:
Uri path = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".helper.ProviderClass", file5);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
请帮帮我。
【问题讨论】:
-
您不能为其他应用声明任何内容。
-
您的旧版请求也仅适用于您自己在 Android 10 设备上的应用。
-
@blackapps 那么如何访问另一个应用程序来查看 PDF 文件?
-
以正常方式使用 ACTION_VIEW。
-
shows eacces permission denied issue.访问什么?您在哪里看到这个问题?
标签: android android-permissions android-external-storage android-fileprovider accessibility