【发布时间】:2019-06-07 02:21:52
【问题描述】:
我正在尝试使用现有已安装的 pdf 应用程序(例如 Google PDF Viewer)打开 pdf。但 PDF 屏幕显示空白。
我创建了一个意图并使用了ACTION_VIEW 过滤器,但是当我在 Google PDF 中打开它时,它只显示空白屏幕,即使 Google PDF 中的文件名也不可见,只有文档 ID (content-provider://.. ../document/122
String filePath = "content://com.android.providers.downloads.documents/document/346";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(filePath), "application/pdf");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
mActivity.startActivity(Intent.createChooser(intent, "select an app to open this file"));
【问题讨论】:
-
您检查您的
Uri是否有效?我的意思是它是否指向有效的 pdf 数据? -
由于您可能没有对该文档的读取权限,因此您无法授予其他人读取权限。你从哪里得到
Uri,你为什么要硬编码它? -
它不是硬编码的,我把它作为参考。我正在存储从 SQLite 中的文件选择器获取的内容 URI,然后我使用相同的 URI 来显示 pdf。我该怎么做?
标签: android uri android-contentprovider