一、简介

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

二、集成

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

TEST_APPID为测试appid,上线请替换正式的APPID

UNAD.initialize(new UNADConfig.Builder()
                            // true-屏蔽个性化推荐广告(关闭)
                            //false-不屏蔽个性化推荐广告(打开)
                            //默认false
                            .setPersonalRecommend(false)
                            .setDebug(true).build(),
                    "TEST_APPID", this, new UNAD.InitCallback() {
                        @Override
                        public void onSuccess() {

                            Log.e("unadsdk", "UI:onSuccess");
                        }

                        @Override
                        public void onError(UnadError error) {
                            Log.e("unadsdk", "UI:onError");
                        }
                    });

2、初始化广告

     rewarded = new UNADRewarded(this, adid, new UNADRewarded.UNADRewardedListener() {
                @Override
                public void onADReceive() {
                }

                @Override
                public void onADPresent() {
                }

                @Override
                public void onReward(Map<String, Object> var1) {
                }

                @Override
                public void onADClicked() {

                }

                @Override
                public void onVideoComplete() {
                }

                @Override
                public void onClose() {

                }

                @Override
                public void onADError(UnadError var1) {

                }
            });

3、校验广告有效性

 rewarded.isAdValid()

5、打开广告

打开前检查广告是否有效

  if (null == rewarded) {
            Toast.makeText(this, "请先加载广告", Toast.LENGTH_SHORT).show();
            return;
        }
        if (rewarded.isAdValid()) {
            rewarded.show(this);
        } else {
            Toast.makeText(this, "广告失效,请重新加载", Toast.LENGTH_SHORT).show();
        }

6、销毁广告

if (rewarded != null) {
      rewarded.destroy();
 }

7、设置视频广告是否打开声音

设置视频是否打开声音true是false否

interstitial.enableAudio(true);

8、注意事项

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

results matching ""

    No results matching ""