Demand:
When the app launches, it gets a link to the ad image, and if it already exists, decide if it's the same as the local, and then download it locally.
Flow chart:
These are all on the previous page of the ad page (Logo page or application)
Importandroid.content.Intent;Importandroid.text.TextUtils;ImportCOM.XUEHU365.XUEHU.R;ImportCom.xuehu365.xuehu.business.SplashImgDownLoader;ImportCom.xuehu365.xuehu.data.UserData;Importcom.xuehu365.xuehu.model.response.AdResponseEntity;ImportCom.xuehu365.xuehu.netinterface.AdAPI;ImportCom.xuehu365.xuehu.netinterface.retrofit.BaseCallBack;ImportJava.util.Timer;ImportJava.util.TimerTask;ImportRetrofit2. Response; Public classLogoactivityextendsbasefragmentactivity {@OverrideprotectedObject Getcotentview () {returnR.layout.activity_logo; } @Overrideprotected voidInitview () {Super. Initview (); Checkadurl (); Jump (); } Private voidCheckadurl () {Adapi.getad (NewBasecallback<adresponseentity>() {@Override Public voidOnsuccess (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 voidJump () {FinalTimer timer =NewTimer (); Timer.schedule (NewTimerTask () {@Override Public voidrun () {if(NULL!=timer) {Timer.cancel (); StartActivity (NewIntent (logoactivity. This, Splashactivity.class)); Finish (); } } }, 1000); }}
ImportCom.liulishuo.filedownloader.BaseDownloadTask;ImportCom.liulishuo.filedownloader.FileDownloadListener;ImportCom.liulishuo.filedownloader.FileDownloader;ImportCom.xuehu365.xuehu.data.UserData;ImportCom.xuehu365.xuehu.utils.PathUtil;ImportJava.io.File;/*** Created by Administrator on 2017/8/8.*/ Public classSplashimgdownloader { Public Static voiddownLoad (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 (NewFiledownloadlistener () {@Overrideprotected voidPending (Basedownloadtask task,intSofarbytes,inttotalbytes) {} @Overrideprotected voidProgress (Basedownloadtask task,intSofarbytes,inttotalbytes) {} @Overrideprotected voidcompleted (basedownloadtask Task) {Userdata.saveadbitmap (Task.getpath ()); } @Overrideprotected voidPaused (basedownloadtask task,intSofarbytes,inttotalbytes) {} @Overrideprotected voidError (basedownloadtask task, Throwable e) {} @Overrideprotected voidwarn (basedownloadtask Task) {}}); Task.start (); }}
Then, the ad page just needs to go to the local address and load it.
App Launch ads