Android 打开pdf文档,没有阅读器链接到Google Play Store等下载
16lz
2021-01-23
使用自带的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
更多相关文章
- Android 各种类型的资源 文件
- Android系统各种类型的service刨根解读
- Android之SQLite存取DATETIME类型
- 重点核心☆☆☆☆☆按钮点击事件的四种类型
- Android 中常用 MimeType 及对应文件类型
- Android 常用mimetype类型
- Android: 判断网络连接状态及连接类型
- Android判断文件类型(视频、音频、图片等)