標籤:連結 adl logo can java dbi owa index load
需求:
App啟動的時候獲得廣告圖片連結,如果已經存在,判斷是否和本地的相同,不相同才去下載到本地。
流程圖:
這些都在廣告頁的前一個頁面操作(logo頁或者Application)
import android.content.Intent;import android.text.TextUtils;import com.xuehu365.xuehu.R;import com.xuehu365.xuehu.business.SplashImgDownLoader;import com.xuehu365.xuehu.data.UserData;import com.xuehu365.xuehu.model.response.AdResponseEntity;import com.xuehu365.xuehu.netinterface.AdAPI;import com.xuehu365.xuehu.netinterface.retrofit.BaseCallBack;import java.util.Timer;import java.util.TimerTask;import retrofit2.Response;public class LogoActivity extends BaseFragmentActivity { @Override protected Object getCotentView() { return R.layout.activity_logo; } @Override protected void initView() { super.initView(); checkAdUrl(); jump(); } private void checkAdUrl() { AdAPI.getAd(new BaseCallBack<AdResponseEntity>() { @Override public void onSuccess(Response<AdResponseEntity> response) { AdResponseEntity.Data data = response.body().getData(); if (null == data) { return; } String url = data.getUrl(); if (TextUtils.isEmpty(url)) { return; } String localAd = UserData.getAdBitmap(); if (!TextUtils.isEmpty(localAd)) { String urlFileName = url.substring(url.lastIndexOf("/") + 1); String localFileName = localAd.substring(localAd.lastIndexOf("/") + 1); if (urlFileName.equals(localFileName)) { return; } } SplashImgDownLoader.downLoad(url); } }); } private void jump() { final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { if (null != timer) { timer.cancel(); startActivity(new Intent(LogoActivity.this, SplashActivity.class)); finish(); } } }, 1000); }}
import com.liulishuo.filedownloader.BaseDownloadTask;import com.liulishuo.filedownloader.FileDownloadListener;import com.liulishuo.filedownloader.FileDownloader;import com.xuehu365.xuehu.data.UserData;import com.xuehu365.xuehu.utils.PathUtil;import java.io.File;/** * Created by Administrator on 2017/8/8. */public class SplashImgDownLoader { public static void downLoad(String url) { String fileName = url.substring(url.lastIndexOf("/") + 1); String filePath = PathUtil.getInstance().getImagePath() + File.separator + fileName; BaseDownloadTask task = FileDownloader.getImpl().create(url).setPath(filePath).setListener(new FileDownloadListener() { @Override protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) { } @Override protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) { } @Override protected void completed(BaseDownloadTask task) { UserData.saveAdBitmap(task.getPath()); } @Override protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) { } @Override protected void error(BaseDownloadTask task, Throwable e) { } @Override protected void warn(BaseDownloadTask task) { } }); task.start(); }}
然後,廣告頁只需要去本地拿地址然後載入就可以了
App啟動廣告