【问题标题】:Best way to download images on Android在 Android 上下载图像的最佳方式
【发布时间】:2014-10-19 10:15:35
【问题描述】:

我正在开发一个使用多个图像的 Android 应用程序,我想在网络服务器上传输更大的图像 (2-6 MB) 以便在需要时下载它们。
我以前从未尝试过,所以我找到了一种使用 AsyncTask 在按钮单击时下载图像的方法,这是最好的解决方案吗?

有更好的选择或意见吗?


编辑:我正在尝试 koush 的 ion

编辑 2: 我尝试了 ion ( https://github.com/koush/ion) 我非常喜欢这里,非常易于使用。建议

【问题讨论】:

标签: java android android-download-manager imagedownload


【解决方案1】:
   Use Universal image loader for downloading images asynchronously.  

  [https://github.com/nostra13/Android-Universal-Image-Loader][1].


  The Library itself has a sample code to download image.you may refer it..


  [1]: https://github.com/nostra13/Android-Universal-Image-Loader
After downloading library  add library with your project and insert the below code at necessary place


String final_url="www.google.com/.....";
ImageView image;

ImageLoader  imageloader = ImageLoader.getInstance();

imageloader.init(ImageLoaderConfiguration.createDefault(context));

DisplayImageOptions options; = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.ic_empty)
                .showImageOnFail(R.drawable.ic_error)
                .resetViewBeforeLoading(true).cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
                .cacheInMemory(true)
                .displayer(new FadeInBitmapDisplayer(300)).build();
imageloader.displayImage(final_url, image);

【讨论】:

    【解决方案2】:

    我强烈建议使用 Glide 或 Picasso,它们是当今最常用的库。 只需谷歌“Glide for Android”或“Picasso for Android”,他们就会处理线程、缓存、优化等。 希望对你有帮助!

    【讨论】:

      【解决方案3】:

      最佳实践: http://developer.android.com/training/displaying-bitmaps/index.html。 有用的库: 毕加索 - http://square.github.io/picasso; 滑翔 - github.com/bumptech/glide。

      【讨论】:

        【解决方案4】:

        实际上,使用AsyncTask 的最重要原因是您想要一种机制来执行冗长的操作而不会阻塞您的 UI。有了它,您还可以摆脱管理子线程和同步。就是这样。如果您想要其他功能,例如位图缓存,则必须自己实现或使用一些第三方工具。

        【讨论】:

          【解决方案5】:

          【讨论】:

            猜你喜欢
            • 2014-01-27
            • 2011-07-17
            • 1970-01-01
            • 2023-03-13
            • 1970-01-01
            • 2016-09-08
            • 1970-01-01
            • 1970-01-01
            • 2011-09-03
            相关资源
            最近更新 更多