我有这个功能可以在设备中下载和保存图像 -
public void DownloadFromUrl(String WebURL, String fileName) {
try {
URL url = new URL(WebURL);
file = new File(context.getFilesDir() + fileName+".jpg");
long startTime = System.currentTimeMillis();
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
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();
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
如果我提供 https URL,它无法保存图像。关于如何下载和保存 https 图像的任何指示?
最佳答案
希望此链接对您有所帮助。 Tonikami 上传/下载图片。
https://www.youtube.com/playlist?list=PLe60o7ed8E-Q7tqKNPnWFdUoeniqH_-A9
关于android - 在android中从https URL下载和保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35332747/