我想将图片从网址下载到本地存储,并将图片从本地存储打开到imageview?
我看到了这些答案
How to download and save an image in Android
downloading images with Picasso android disck
Saving image from URL using Picasso?
我知道我们可以使用 Picasso 和 Glide 和 Volley 以及 Universal Image Loader 来完成这些工作还有其他图书馆...
但我无法实现下载图片的代码!并且在互联网上找不到任何新的例子。 我找到了毕加索库旧版本
的一些旧例子你能给我一些新的下载图片代码,从URL上网到本地存储或任何关于这个主题的教程讨论
答案 0 :(得分:1)
答案 1 :(得分:0)
使用下载管理器从链接(来自互联网)下载图像
DownloadManager downloadManager = (DownloadManager) ((Activity) context).getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle(fileName)
.setDescription("file description")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(imgStoragePath, fileName)
.setVisibleInDownloadsUi(true);
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
//Download complete
}
};
context.registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
downloadManager.enqueue(request);