我们的眼睛就是我们的监狱,我们的眼光所到之处就是我们监狱的围墙。——尼采
首先请求授权
然后我们这里引入依赖
代码语言:javascript复制implementation 'com.hujiang.restvolley:restvolley:1.0.1'
然后调用函数
代码语言:javascript复制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
下载图片到本地啦!
源码地址