Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

android - Download PDF from url and read it

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...