我在这么基本的东西上撞墙。我想要做的是使用任何安装了Adobe Reader的PDF阅读器程序打开PDF文件。但是,当我检查是否有任何已注册为“ application / pdf”的已安装应用程序时,即使我已经安装了Adobe Reader,它也始终返回null。这是我正在使用的代码:
String pdfFile = "android.resource://" + getPackageName() + "/" + R.raw.middleburychamberweb2014;
Intent pdfIntent = null, chooser=null;
pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(Uri.parse(pdfFile), "application/pdf");
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(pdfIntent, 0);
if (pdfIntent.resolveActivity(getPackageManager()) != null) {
chooser = Intent.createChooser(pdfIntent,"Select Viewer for PDF file");
startActivity(chooser);
} else {
/* No PDF reader found on device. Provide user the option to
* install the Adobe Reader found on Google Play.
*/
Log.e("Directory","No PDF viewers!");
noPDFReader(getString(R.string.doc1web));
}
曾经写过的大约零个应用程序采用了晦涩的android:resource
方案,这就是为什么这种方案不起作用的原因。
我同意323go -使用ContentProvider
,如FileProvider
。只需使用,就需要在提供者端实现零行Java代码FileProvider
。它要求清单清单,一个元数据XML文件以及在调用startActivity()
时允许一行以允许PDF查看器访问内容。这比写入外部存储更具前瞻性,并且更加安全。
FWIW,我有一个示例项目,演示了通过来将PDF提供给外部PDF查看器FileProvider
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句