保存文件时要使用RxJava的doOnNext、map等操作符,后续更新UI的操作切换到UI线程。主线程中应该避免耗时操作
retrofit.create(ApiService.class)
.dowmBitmap("http://imgcache.qq.com/qzone/space_item/pre/0/66768.gif")
.compose(this.bindToLifecycle())
.subscribeOn(Schedulers.newThread())
.map(newFunction() {
@Override
public String apply(ResponseBody responseBody)throwsException { //返回类型可以自己更改
return FileUtils.saveBitmap(mContext,responseBody.byteStream(),HttpConfig.IMAGE_PATH, null,"gif", false, true);//图片保存
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(newConsumer() {
@Override
public void accept(String s)throwsException {
if(s !=null&& s.length() >0) {
QQApiRequest.get().shareImage(mContext,s, true);
}else{
T.showMessage(mContext,"gif下载失败");
}
}
});