我在我的android应用程序中使用ok-http。使用OKHTTP下载pdf文件
我有来自网络服务.pdf文件的网址。
我必须在ImageView的点击事件下载pdf文件。我在谷歌搜索它,但无法找到具体的答案。
请提供给我解决方案,如果有人知道它。 谢谢。
我在我的android应用程序中使用ok-http。使用OKHTTP下载pdf文件
我有来自网络服务.pdf文件的网址。
我必须在ImageView的点击事件下载pdf文件。我在谷歌搜索它,但无法找到具体的答案。
请提供给我解决方案,如果有人知道它。 谢谢。
查看官方OkHttp的食谱: https://github.com/square/okhttp/wiki/Recipes
即使世界是一个很多工作要做,以实现这一目标,我还在上实现对PDF文件一样的东西的工作,但这里的一些代码,为我工作下载图像文件:
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/ergonomics/pdf_test");
myDir.mkdirs();
String fname = "TestPdf-01A.pdf";
File file = new File(myDir, fname);
if (file.exists()) file.delete();
InputStream is = response.body().byteStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
只是FYI ByteArrayBuffer已被弃用,所有的Apache的东西在Android的网络。但是,从理论上讲,它是有效的,并且应该很容易遵循。
发布你迄今为止所做的一切! –