App啟動廣告

來源:互聯網
上載者:User

標籤:連結   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啟動廣告

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.