After setting up the SDK as described in Monetization Quick Start, you are ready to display a modal Sushi ad.

Requesting an ad may not display it right away. Your request is added to a queue and is treated as soon as the ad is available. This is the reason why we recommend that you check its availability before anything else.

Check if a modal ad is available

An ad won't necessarily be available as soon as the SDK is initialized. The library will need to sync with our servers. So before you request an ad, you should check its availability! There is a simple way to do that.

if (m_adSdk.isAModalAdOfTypeAvailable("SUSHI_ZONE_ID", AFAdSDKModalType.AFAdSDKModalTypeSushi)) {
    // sushi ad is available
}

SUSHI_ZONE_ID is the zone ID for your Sushi interstitials, as provided by Appsfire.

The method isAModalAdOfTypeAvailable() returns true or false:

  • true: an ad is available right now
  • false: no ad is available right now

Request a modal ad

Once you know a modal ad is available, you can request it via requestModalAd method.

The method is asynchronous. You may request an ad to present itself as soon as possible. Or you may wait for an ad to be available, and present it almost right away.

Let's say you are in a breakout session, you could request an ad this way:

// Check if a modal ad of type Sushi is available
if (m_adSdk.isAModalAdOfTypeAvailable("SUSHI_ZONE_ID", AFAdSDKModalType.AFAdSDKModalTypeSushi)) {
    try {
        // Request modal ad
        m_adSdk.requestModalAd("SUSHI_ZONE_ID", AFAdSDKModalType.AFAdSDKModalTypeSushi, this);
    } catch (AFAdAlreadyDisplayedException e) {
    }
}
else {
    // Continue normal behavior
}

Again SUSHI_ZONE_ID is the zone ID for your Sushi interstitials, as provided by Appsfire.

That's it, you are now serving Sushi ads! You can also consult the Sushi App example from the SDK for more information. To do so, please import an existing project into your Eclipse workspace and select the appsfire_simpleSushiApp folder from the unpacked Appsfire SDK.

Receiving ad events

If you want to be alerted of the availability of a modal ad when your app is launching, you can set up event handling.

Set an event handler for Ad SDK events in your Activity's onCreate() above the call to prepare():

    // Get ad events
    m_adSdk.setEventsDelegate(new MySampleAppEventsDelegate());

    // Call prepare() as we already did before
    m_adSdk.prepare (this);

Finally, define the events handler:

  /**
   * Handle events dispatched by the ad SDK
   */

  static class MySampleAppEventsDelegate implements AFAdSDKEventsDelegate {
      @Override
      public void onEngageSDKInitialized() {
          // SDK initialized
          Log.i (CLASS_TAG, "onEngageSDKInitialized");
      }

      @Override
      public void onAdUnitInitialized() {
          // Ad unit initialized
          Log.i (CLASS_TAG, "onAdUnitInitialized");
      }

      @Override
      public void onAdsLoaded() {
          // Ads metadata downloaded
          Log.i (CLASS_TAG,"onAdsLoaded");
      }

      @Override
      public void onModalAdAvailable(String zoneId) {
          // A modal ad (sushi interstitial) is available
          Log.i (CLASS_TAG, "onModalAdAvailable for zone " + zoneId);
      }

      @Override
      public void onInStreamAdAvailable(String zoneId) {
          // One or more in-stream (sashimi) ads are available
          Log.i (CLASS_TAG,"onInStreamAdAvailable for zone " + zoneId);
      }

      @Override
      public void onNativeAdAvailable(String zoneId) {
          // One or more native ads available
          Log.i (CLASS_TAG,"onNativeAdAvailable for zone " + zoneId);
      }

      @Override
      public void onModalAdPreDisplay() {
          // A modal ad is about to display
          Log.i (CLASS_TAG,"onModalAdPreDisplay");
      }

      @Override
      public void onModalAdDisplayed() {
          // A modal ad is displayed
          Log.i (CLASS_TAG,"onModalAdDisplayed");
      }

      @Override
      public void onModalAdFailedToDisplay(AFAdSDKError errCode) {
          // A modal ad failed to display
          Log.i (CLASS_TAG,"onModalAdFailedToDisplay");
      }

      @Override
      public void onModalAdPreDismiss() {
          // A modal ad is about to close
          Log.i (CLASS_TAG,"onModalAdPreDismiss");
      }

      @Override
      public void onModalAdDismissed() {
          // A modal ad has closed
          Log.i (CLASS_TAG,"onModalAdDismissed");
      }

      @Override
      public void onLeaveApplication() {
          // Leaving application
          Log.i (CLASS_TAG,"onLeaveApplication");
      }

      @Override
      public void onModalAdClicked() {
          // Modal ad clicked
          Log.i (CLASS_TAG, "modal ad clicked");        
      }

      @Override
      public void onInStreamAdClicked() {
          // In-stream ad clicked
          Log.i (CLASS_TAG, "in-stream ad clicked");        
      }

      @Override
      public void onNativeAdClicked() {
          // Native ad clicked
          Log.i (CLASS_TAG, "native ad clicked");       
      }
}

Please refer to the appsfire_simpleSushiApp or appsfire_antExampleApp projects in the SDK for a full example of using Sushi ads.