Splash广告集成说明

开屏(Splash)

1. 确定AdHubSDK的主SDK文件已经拷贝到工程文件的libs子目录下参考

2. 在需要添加开屏广告的Activity对应的布局文件添加一个ViewGroup来给样式定位

  • 例如:
<FrameLayout android:id="@+id/adsFl"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_above="@id/bottomRl"></FrameLayout>

3. 添加广告代码,添加广告代码前请确定已初始化SDK

  • 例如:
    // adUnitContainer
    FrameLayout adsParent = (FrameLayout) this.findViewById(R.id.adsFl);

    // the observer of AD
    AdListener listener = new AdListener() {
        @Override
        public void onAdLoaded() {
            Log.i("SplashActivity", "onAdShown");
        }

        @Override
        public void onAdShown() {
            Log.i("SplashActivity", "onAdShown");
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Log.i("SplashActivity", "onAdFailedToLoad");
            jump();
        }

        @Override
        public void onAdClosed() {
            Log.i("RSplashActivity", "onAdDismissed");
            jumpWhenCanClick(); // 跳转至您的应用主界面
        }

        @Override
        public void onAdClicked() {
            Log.i("SplashActivity", "onAdClick");
            // 设置开屏可接受点击时,该回调可用
        }
    };
    AdHub.initialize(this, appId);
    new SplashAd(this, adsParent, listener, splashAdUnitId);
  • 构造SplashAd:
    // adsParent: 放置SplashAd的ViewGroup
    // listener:  事件监听器
    // splashAdUnitId: 广告位ID
    new SplashAd(this, adsParent, listener, splashAdUnitId);
  • AdLisenter接口定义:
// A listener for receiving notifications during the lifecycle of an ad.
public abstract class AdListener {

    // Constructor
    protected AdListener() {
    }

    // Called when an ad is received.
    public void onAdLoaded() {
    }

    // Called when an ad become visible.
    public void onAdShown() {
    }

    // Called when an ad request logFailed. The error code is usually ERROR_CODE_INTERNAL_ERROR,
    // ERROR_CODE_INVALID_REQUEST, ERROR_CODE_NETWORK_ERROR, or ERROR_CODE_NO_FILL.
    public void onAdFailedToLoad(int errorCode) {
    }

    // Called when an ad leaves the application (e.g., to go to the browser).
    public void onAdLeftApplication() {
    }

    // Called when the user is about to return to the application after clicking on an ad.
    public void onAdClosed() {
    }

    // Called when an ad opens an overlay that covers the screen.
    public void onAdOpened() {
    }

    // Called when an ad is clicked.  The current activity will be
    // paused as the user switches to the activity launched from the
    // ad interaction.  For example, the user may click a link that
    // opens a web browser, or touch a click-to-call link which
    // launches the phone dialer.
    public void onAdClicked() {
    }
}

PS:更多设置请参考Demo中的com.hubcloud.adhubsdkdemo.SplashActivity的代码.

results matching ""

    No results matching ""