从url下载PDF并阅读它

时间:2011-12-05 09:53:58

标签: android

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);
}

首先,我尝试从网址下载pdf。 其次,我尝试阅读上面的pdf下载。 但它可能无法下载完成。 如果我想等待pdf下载完成。 我该怎么办?

1 个答案:

答案 0 :(得分:6)

作为替代方案,您可以尝试在Google文档中打开pdf。请尝试以下代码 -

   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);