51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

超级简单的安卓图片下载

我们的眼睛就是我们的监狱,我们的眼光所到之处就是我们监狱的围墙。------尼采

首先请求授权

然后我们这里引入依赖

|-----------|-----------------------------------------------------------------------------| | 1 | hljs gradle implementation 'com.hujiang.restvolley:restvolley:1.0.1' |

然后调用函数

|---------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | hljs java String filename = url.substring(url.lastIndexOf("/")); String localPath = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) + filename; RestVolleyDownload.download(context, url, localPath, new RestVolleyDownload.OnDownloadListener() { @Override public void onDownloadStart(String url) { } @Override public void onDownloadSuccess(String url, File file, int httpCode, Headers headers) { ToastUtils.shortToast("保存成功,文件地址:" + localPath); } @Override public void onDownloadFailure(String url, Exception e, int httpCode, Headers headers) { ToastUtils.shortToast("保存失败"); } @Override public void onDownloadProgress(String url, int downloadBytes, int contentLength, File file, int httpCode, Headers headers) { } }); |

就能实现根据网络图片url下载图片到本地啦!

源码地址

赞(0)
未经允许不得转载:工具盒子 » 超级简单的安卓图片下载