android如何将图像形式下载到本地存储?

时间:2018-05-09 22:30:40

标签: android image url save internal-storage

我想将图片从网址下载到本地存储,并将图片从本地存储打开到imageview?

我看到了这些答案

How to download and save an image in Android

Download images and save it

downloading images with Picasso android disck

Saving image from URL using Picasso?

我知道我们可以使用 Picasso Glide Volley 以及 Universal Image Loader 来完成这些工作还有其他图书馆...

我无法实现下载图片的代码!并且在互联网上找不到任何新的例子。  我找到了毕加索库旧版本

的一些旧例子

你能给我一些新的下载图片代码,从URL上网到本地存储任何关于这个主题的教程讨论

2 个答案:

答案 0 :(得分:1)

试试这个...

使用此gradle:https://github.com/amitshekhariitbhu/Fast-Android-Networking

并检查这一点:从服务器下载文件

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