Interstitial Ad

If you use jar for integration, please declare InterstitialAdActivity to AndroidManifest.xml

<activity
  android:name="com.intowow.sdk.InterstitialAdActivity"
  android:configChanges="orientation|screenSize"
  android:launchMode="singleTask"
  android:screenOrientation="portrait"
  android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>

Initialize InterstitialAd class

import com.intowow.sdk.InterstitialAd;

private InterstitialAd mInterstitialAd = null;
private final static String PLACEMENT_NAME = "Obtain from your Intowow account manager";

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mInterstitialAd = new InterstitialAd(mActivity);
}

NOTE : please make sure to pass Activity on to the InterstitialAd.

Setup the RequestInfo

  • You need to set the placement ID and the request timeout in requestInfo.

RequestInfo requestInfo = new RequestInfo();
requestInfo.setPlacement(PLACEMENT_NAME);
requestInfo.setTimeout(timeout);

Load ad with RequestInfo

loadAdInstant

import com.intowow.sdk.CERequestResult;

CERequsetResult result = mInterstitialAd.loadAdInstant(requestInfo);
 if (result.isSuccess()) {
                // TODO: Attach the Ad View
            } else {
                // You can call result.getError() to know info of loadAd fail
            }
}

With loadAdInstant , our synchronous method , You will get the result of loading ad by CERequestResult directly.

loadAdAsync

import com.intowow.sdk.CEAdRequestListener;
import com.intowow.sdk.CEInterstitialAdListener;

mInterstitialAd.loadAdAsync(requestInfo, new CEAdRequestListener() {
        @Override
            public void onError(Ad ad, AdError error) {
            }

        @Override
            public void onAdLoaded(Ad ad) {
                if(mInterstitialAd != ad) {
                    return;
                }
                //  Start InterstitialAdActivity for showing this ad.
                //
                mInterstitialAd.show();      
            }
    });

loadAdAsync is an asynchronous method, you can set timeout via RequestInfo, and get the result of ad request by CEAdRequestListener.

Add CEInterstitialAdListener to get the result of ad request and ad event callback.

import com.intowow.sdk.Ad;
import com.intowow.sdk.AdError;
import com.intowow.sdk.InterstitialAd;
import com.intowow.sdk.CEInterstitialAdListener;

private InterstitialAd mInterstitialAd = null;
private final static String PLACEMENT_NAME = "Obtain from your Intowow account manager";

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mInterstitialAd = new InterstitialAd(mActivity, PLACEMENT_NAME);

  mInterstitialAd.setAdListener(new CEInterstitialAdListener() {

    @Override
    public void onAdDisplayed(Ad ad) {
    }

    @Override
    public void onAdDismissed(Ad ad) {
    }

    @Override
    public void onAdClicked(Ad ad) {
    }

    @Override
    public void onAdImpression(Ad ad) {
    }

    @Override
    public void onAdMute(Ad ad) {
    }

    @Override
    public void onAdUnmute(Ad ad) {
    }

    @Override
    public void onVideoEnd(Ad arg0) {
    }

    @Override
    public void onVideoProgress(Ad arg0, int totalDuration, int currentPosition) {
    }

    @Override
    public void onVideoStart(Ad arg0) {
    }

  });
}

Release ad when the Activity is destroyed

@Override
protected void onDestroy() {
    if(mInterstitialAd != null) {
        mInterstitialAd.destroy();
        mInterstitialAd = null;
    }
    ...
    ...
    super.onDestroy();
}

Handle Landscape Orientation

There are two options to handle landscape orientation.

  • Add android:configChanges="orientation|screenSize in AndroidManifest.xml.

  • If ad is displayed in landscape mode, your Activity will be recreated. You can have a variable to remember if you’ve requested interstitial ad or not in onSaveInstanceState(). Later you can retrieve that variable in onCreate() and avoid requesting interstitial ad twice. See BaseActivity.java in sample app source code.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //...

    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(KEY_HAS_INTERSTITIAL_AD)) {
            mHasInterstitialAd = savedInstanceState.getBoolean(KEY_HAS_INTERSTITIAL_AD);
            savedInstanceState.remove(KEY_HAS_INTERSTITIAL_AD);
        }
    }

    if(!mHasInterstitialAd) {
      //  load ad
      //
    }
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putBoolean(KEY_HAS_INTERSTITIAL_AD, mInterstitialAd != null);
    super.onSaveInstanceState(outState);
}

private boolean hasRequestedInterstitialAd() {
    return mHasInterstitialAd;
}

If you want to get more information about integration, please refer to InterstitialAd class.

Last updated