Android 打开pdf文档,没有阅读器链接到Google Play Store等下载

来源:互联网 发布:js调用手机图库 编辑:程序博客网 时间:2024/04/29 00:40

使用自带的pdf阅读器,打开pdf文档。如果没有阅读器,链接到android市场(Google Play Store,360手机助手等)下载。

File file = new File(pdfPath);Intent intent = new Intent("android.intent.action.VIEW");intent.addCategory("android.intent.category.DEFAULT");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.setDataAndType(Uri.fromFile(file), "application/pdf");try {    startActivity(intent);} catch (ActivityNotFoundException e) {    Intent marketIntent = new Intent(Intent.ACTION_VIEW);    marketIntent.setData(Uri.parse("market://search?q=PDF"));    startActivity(marketIntent);}

必须加try{}catch{}, 否则,如果没有阅读器,程序会崩溃报错ActivityNotFoundException。

想要了解更多market://的知识,请点击http://blog.csdn.net/liucaoye/article/details/41449059

想要了解各种类型文件(“.html”,".doc",".mp3"上百种类型)对应的setDataAndType的参数,参考 http://www.2cto.com/kf/201201/117389.html

想要了解Intent的各种跳转(email,短信,map,电话等),参考http://luhuajcdd.iteye.com/blog/1560225


0 0
原创粉丝点击