一、简介

主要介绍在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、初始化广告

    unadrewarded= new UNADRewarded(RewardedActivity.this);
        unadrewarded.setAdUnitId("UNAD_TEST_UNIT_ID");

3、监听状态

 unadrewarded.setAdViewListener(new UNADRewarded.AdViewListener() {
                    @Override
                    public void onAdViewLoaded() {

                    }


                    @Override
                    public void onAdViewFailed(AdError error) {

                    }

                    @Override
                    public void onAdViewClose() {


                    }

                    @Override
                    public void onAdViewExpanded() {

                    }

                    @Override
                    public void onUserEarnedReward() {

                    }

4、加载广告

 unadrewarded.loadAd();

5、打开广告

打开前检查广告是否有效

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

6、注意事项

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

2、自定义admob广告请参考DEMO中的FeedActivity

results matching ""

    No results matching ""