从以下网址下载PDF文档阅读它 [英] Download PDF from url and read it

查看:136
本文介绍了从以下网址下载PDF文档阅读它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void openDocumentWithInstalledApp(String filename) {
String mimetype = "";
url = url+ filename;
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://" + url;
}
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);

/*what should I do?*/

mimetype = "application/pdf";
File file = new File("/mnt/sdcard/Download/" + filename);
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setDataAndType(Uri.fromFile(file), mimetype);
intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent1);
}

首先,我尝试从URL下载一个PDF文件。 第二,我试着读上面下载PDF。 但它可能无法下载完成。 如果我要等待的PDF下载完成。 我该怎么办?

First, I try to download a pdf from url. Second, I try to read the pdf above download. But it may not download finish. If I want to wait the pdf download finish. What should I do?

推荐答案

作为一种替代方法,你可以尝试在谷歌文档打开PDF文件。尝试下面code -

As an alternative you can try opening pdf in google docs. Try below code-

   String pdfurl = "http://www.example.com/yourfile.pdf";
   String googleDocsUrl = "http://docs.google.com/viewer?url="+pdfurl;
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");
   startActivity(intent);

这篇关于从以下网址下载PDF文档阅读它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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