1) Android

Before proceeding this chapter, be sure that you already finished SDK settings. If not, check 3) Android Settings first.

[Incentive Interstitial Ad]

To display incentive interstitial ads in your app, simply write down two lines of code as follows.

Incentive Ad Sample

TnkSession.prepareInterstitialAd(this, TnkSession.PPI);

TnkSession.showInterstitialAd(this);



[Non-Incentive Intestitial Ad]

To display non-incentive interstitial ads in your app, simply write down two lines of code as follows.

Non-Incentive Ad Sample

TnkSession.prepareInterstitialAd(this, TnkSession.CPC);

TnkSession.showInterstitialAd(this);


[TnkAdListener]

To catch events when an interstitial ad is loaded or users close interstitial ads, use TnkAdListener interface.

TnkAdListener Interface

public interface TnkAdListener {


// User closed view by clicking close button or pressing back-key

public static final int CLOSE_SIMPLE = 0;


// User clicked an ad and the view is closed

public static final int CLOSE_CLICK = 1;


// User clicked 'exit' button in the view

public static final int CLOSE_EXIT = 2;

public static final int FAIL_NO_AD = -1;  // no ad available

public static final int FAIL_NO_IMAGE = -2; // ad image not available

public static final int FAIL_TIMEOUT = -3; // ad not arrived in timeout.

public static final int FAIL_CANCELED = -4; // skip by ad frequency settings 

public static final int FAIL_NOT_PREPARED = -5; // prepare not invoked.

public static final int FAIL_SYSTEM = -9;


/**

         * Invoked when popup view is closed 

         * Reason type is passed in type parameter.

         * @param type 

         */

public void onClose(int type);

/**

 * Invoke when popup view is shown up.

 */

public void onShow();

/**

* Invoked when failed to display ad.

 * Error code is passed in errCode parameter.

*/

public void onFailure(int errCode);

/**

* Invoked when an interstitial ad is loaded.

 * If show() API is invoked before ad is loaded, then onShow() is invoked when an interstitial ad is loaded.

*/

public void onLoad();

}


prepareInterstitialAd() and showInterstitialAd() method can have TnkAdListener object as last parameter.
Following sample code shows that developer can control displaying interstitial ads.

TnkAdListener Sample

        TnkSession.prepareInterstitialAd(this, TnkSession.CPC, new TnkAdListener() {


  @Override

  public void onClose(int type) {

  }


  @Override

  public void onFailure(int errCode) {

  }


  @Override

  public void onLoad() {

  if (isOkToShow) {

  TnkSession.showInterstitialAd(MainActivity.this);

  }

  else {

  // now showing

  }

  }


  @Override

  public void onShow() {

  }

        });

 
[Interstitial Ad APIs]

API specs for prepareInterstitialAd() and showInterstitialAd().

- TnkSession.prepareInterstitialAd()

Method
  - void TnkSession.prepareInterstitialAd(Activity activity, String displayLogic)
  - void TnkSession.prepareInterstitialAd(Activity activity, String displayLogic, TnkAdListener listener)

Description
   It loads a single interstitial Ad from server and cache it in memory.

Parameters
Name Description
 activityActivity object
 displayLogic Enter TnkSession.PPI for incentive ads or TnkSession.CPC for non-incentive ads or any other string for Display Logic. See 3) Display Logic for details.
 listener TnkAdListener object

- TnkSession.showInterstitialAd()

Method
  - void TnkSession.showInterstitialAd(Activity activity)
  - void TnkSession.showInterstitialAd(Activity activity, TnkAdListener listener)
  - void TnkSession.showInterstitialAd(Activity activity, long timeoutMillis)
  - void TnkSession.showInterstitialAd(Activity activity, long timeoutMillis, TnkAdListener listener)

Description
   It displays an interstitial ad which is loaded by prepareInterstitialAd() call before. TnkAdListener.onShow() is invoked when the ads is successfully displayed on screen and TnkAdListener.onFailure() is invoked when the ads is not loaded in timeoutMillis (default is 5000 millisecs).

Parameters
Name Description
 activity Activity object
 listener TnkAdListener object
 timeoutMillis Timeout in millisecs. If ad data from server is not arrived in timeoutMillis then onFailure(FAIL_TIMEOUT) in invoked.
Comments