【发布时间】:2017-07-24 23:43:30
【问题描述】:
我可以使用以下代码从以 *.pdf 结尾的 url 下载和查看
private static final int MEGABYTE = 1024 * 1024;
public static void downloadFile(String fileUrl, File directory){
try {
URL url = new URL(fileUrl);
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
//urlConnection.setRequestMethod("GET");
//urlConnection.setDoOutput(true);
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fileOutputStream = new FileOutputStream(directory);
int totalSize = urlConnection.getContentLength();
byte[] buffer = new byte[MEGABYTE];
int bufferLength = 0;
while((bufferLength = inputStream.read(buffer))>0 ){
fileOutputStream.write(buffer, 0, bufferLength);
}
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
但我尝试下载 url 以 .aspx 结尾的 PDF 文件,因为它会动态生成 PDF 并且无法正常工作。
我也尝试使用 google doc url "http://docs.google.com/viewer?url="+URL 嵌入 webview,但它也不起作用。
有人可以帮忙吗?
【问题讨论】:
标签: android asp.net pdf android-webview pdf-viewer