一、简介

主要介绍在Android项目中如何集成 UNAD SDK的内容Feed流:

二、集成

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

2、初始化流

      //adid为测试广告ID
      UNADContentVideoFeed unadContentVideoFeed =
                new UNADContentVideoFeed(this, adid, getContentVideoFeedListener(adid));
        unadContentVideoFeed.loadAD();

3、初始化监听器

private UNADContentVideoFeed.UNADContentVideoFeedListener getContentVideoFeedListener(final String adid) {
        // 接口回调在主线程,误做耗时操作
        return new UNADContentVideoFeed.UNADContentVideoFeedListener() {
            //广告加载成功
            @Override
            public void onADReceive(UNADFeedPage feedPage) {
                unadFeedPage = feedPage;
                showContentPage();
            }

            @Override
            public void onPageEnter(UNADContentItem item) {
                Log.e(TAG, "onPageEnter");
            }

            @Override
            public void onPageResume(UNADContentItem item) {
                Log.e(TAG, "onPageResume");
            }

            @Override
            public void onPagePause(UNADContentItem item) {
                Log.e(TAG, "onPagePause");
            }

            @Override
            public void onPageLeave(UNADContentItem item) {
                Log.e(TAG, "onPageLeave");
            }

            @Override
            public void onADError(UnadError var1) {
                Log.e(TAG, "onADError:" + var1.getMessage());
            }
        };

    }

4、获取Fragment 并加载

   Fragment fragment=unadFeedPage.getFragment();
        if(null!=fragment){
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container,fragment)
                    .commitAllowingStateLoss();
        }

5、SDK内需要监听Back事件处理业务

   /**
     * SDK内需要监听Back事件处理业务,请按照如下方式回调
     */
    @Override
    public void onBackPressed() {
        if (unadFeedPage != null && unadFeedPage.onBackPressed()) {
            return;
        }
        super.onBackPressed();
    }

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

2、详细参考demo

results matching ""

    No results matching ""