一、简介

主要介绍在Android项目中如何集成 UNAD SDK的插屏广告:

二、集成

1、在自己的Application 中初始化SDK

adgo-app-8379418688为测试appid,上线请替换正式的APPID


      String curProcessName = getProcessName(this);
        if (curProcessName != null && curProcessName.equalsIgnoreCase(this.getPackageName())) {
            //请填写您的APPID
            String unadAppid = "adgo-app-8379418688";
            // 主线程通过调用此方法初始化 SDK。
            UNAD.initialize(unadAppid, getApplicationContext(), new UNAD.InitCallback() {
                @Override
                public void onSuccess() {
                    Log.i(TAG, "onSuccess");
                }

                @Override
                public void onError(AdError error) {
                    Log.i(TAG, "error:" + error.getMessage());
                }

            });
        }

2、初始化广告

  unadInterstitial= new UNADInterstitial(InterstitialActivity.this);
  //测试广告ID UNAD_TEST_UNIT_ID  正式请替换自己的广告ID
  unadInterstitial.setAdUnitId("UNAD_TEST_UNIT_ID");

3、监听状态

  unadInterstitial.setAdViewListener(new UNADInterstitial.AdViewListener() {
                    @Override
                    public void onAdViewLoaded(){

                    }
                    @Override
                    public void onAdViewFailed(AdError error) {

                    }
                    @Override
                    public void onAdViewClose() {

                    }

                    @Override
                    public void onAdViewExpanded() {

                    }
                });

4、加载广告

unadInterstitial.loadAd();

5、打开广告

打开前检查广告是否有效

 if(null!=unadInterstitial&&unadInterstitial.isLoaded()){
                   unadInterstitial.show(InterstitialActivity.this);
               }else{
                   Toast.makeText(
                           InterstitialActivity.this, "Ad is not ready" , Toast.LENGTH_SHORT)
                           .show();
               }

6、注意事项

1、测试广告位ID UNAD_TEST_UNIT_ID 应用上线时请替换为正式的广告位ID

results matching ""

    No results matching ""