UserDefined广告集成说明

自定义(UserDefined)

注: UserDefined是一种可以出现在任意位置, 任意尺寸的插屏广告, 用来满足SDK使用者多变的产品需求.

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

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

  • 例如:
    // Create the InterstitialAd and set the adUnitId.
    // The second parameter is for userDefined type of ad.
    mInterstitialAd = new InterstitialAd(this, true);

    // Defined in res/values/strings.xml
    mInterstitialAd.setAdUnitId(adUnitId);       // 设置广告位ID

    // 设置事件监听器
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            startGame();
        }
    });

    AdRequest adRequest = new AdRequest.Builder().build();
    mInterstitialAd.loadAd(adRequest);
  • 构造InterstitialAd:
    InterstitialAd mInterstitialAd = new InterstitialAd(this, true);
  • 构造AdRequest:
    AdRequest adRequest = new AdRequest.Builder().build();
  • 属性设置: mInterstitialAd.setAdUnitId(adUnitId); // 设置广告位ID mInterstitialAd.setAdListener(adListener); // 设置事件监听器

  • 控制接口: mInterstitialAd.loadAd(adRequest); // 加载广告

  • 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.InterstitialActivity的代码.

results matching ""

    No results matching ""