如何在Android开放PDF [英] How to open PDF in Android

查看:122
本文介绍了如何在Android开放PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从服务器上打开PDF文件,但不保存在设备上,并没有使用任何第三方application.because我不希望我的用户下载任何应用程序使用我的apps.And我不希望使用Web视图打开PDF文件。

How to open pdf file from server without saving it on device and without using any third party application.because i don't want my user to download any application to use my apps.And i don't want to use web view for opening pdf file.

推荐答案

这个方法在旧版本的Andr​​oid的工作:

This method worked in the older versions of android:

在一个新的活动:

        WebView webview = new WebView(this);
        setContentView(webview);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setPluginsEnabled(true);
        webview.loadUrl("http://docs.google.com/gview?embedded=true&url=URL_of_PDF/fileName.pdf");
        setContentView(webview);

在清单文件给予网​​络许可。

使用下面的方法来与已经安装的第三方应用程序中打开PDF文件。

USE the following method to open a PDF file with already installed 3rd party application.

要打开PDF的应用程序中使用:

To open the PDF in application use:

Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

这篇关于如何在Android开放PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆