Get Started

The YaftaMobile Native Extension enables developers to quickly integrate YaftaMobile ads into their Adobe AIR mobile applications. The SDK supports android 2.3 or higher.

Prerequisites

  • Adobe Flash Builder 4.7
  • Adobe AIR SDK version 22 or higher
  • SWF version: 33

Step 1: Import the YaftaMobile AIR Native Extension into your project.

First, import the YaftaMobile native extension into your AIR app. We recommend creating a directory in your project for native extensions, and copy YaftaMobile.ane to that directory. Then add that directory as a native extension directory in your project settings

If you are using Flash Builder, follow these steps:

  1. Right-click your project from the Package Explorer tab.
  2. Select Properties.
  3. Select Flex Build Path from the left navigation area.
  4. Select the Native Extensions tab from the main window.
  5. Click Add ANE (or Add Folder if desired)
  6. Browse to location where the downloaded plugin is located. Make sure Update AIR Application Descriptor is selected.
  7. Select Flex Build Packaging from the left navigation area.
  8. Select Android platform, and then select the Native Extensions tab and check the Package box next to the plugin name
  9. Go to Flex Compiler From the left navigation area, then add -swf-version=33 to Additional compiler arguments

Step 2: Update the App Descriptor

For YaftaMobile to work, you need to make the following changes in the app descriptor manifest file.

  • Include a link to the extension in the descriptor.
  • Add Mandatory Permissions INTERNET, ACCESS_NETWORK_STATE
  • Add a ‘Meta Data’ item called com.yaftamobile.sdk.app.id , with a value of your AppID
  • (Required for interstitials) Add Mandatory activity InterstitialActivity
  • Also Add the Google Play services version ‘Meta-data’ to work properly

Your App Descriptor should have the following:


<manifestAdditions><![CDATA[
   <manifest android:installLocation="auto">
      <!-- These permissions are required for YaftaMobile. -->
      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
   
   
      
      <application>
         <!-- The app ID must be placed here. -->
         <meta-data android:name="com.yaftamobile.sdk.app.id" 
            android:value="YOUR-APPID" /> 

         
         <!-- Only required for interstitials -->
         <activity android:configChanges="keyboard|keyboardHidden|orientation" 
            android:name="com.yaftamobile.sdk.ads.interstitial.InterstitialActivity" />
            
            
            <!-- For Google Play Services (required by YaftaMobile) -->
            <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version" />
            </application>
         </manifest>
]]></manifestAdditions>

<extensions>
    <extensionID>com.yaftamobile.plugins.air</extensionID>
</extensions>

Showing Banner Ads

To display banner ads in your app use the showBanner(adSize:AdSize, bannerPosition:BannerPosition, refreshRate:int) method where:

  • adSize: is one of the following supported ad sizes: FLEXIBLE, S300X50, S320X50, S468X60, S728X90
  • bannerPosition: is one of the following constants, which specify the location of the banner: TOP_CENTER, TOP_LEFT, TOP_RIGHT, BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT
  • refreshRate: is an interval between 30 and 120 seconds

Before you can use YaftaMobile native extension in your code, you need the following import declaration:

 import com.yaftamobile.plugin.air.*;

Add the following code to show banner:

 YaftaMobile.showBanner(AdSize.FLEXIBLE, BannerPosition.BOTTOM_CENTER , 60);

Use the following to hide/re-show the banner:

YaftaMobile.pauseBanner(); // hide banner if visible
YaftaMobile.resumeBanner();  // show banner if not visible

Showing Interstitials

To show an interstitial ad you need to load it first using the loadInterstitial() method, then if loaded successfuly, call the method showInterstitial() to show the ad on the screen.

You can detect if an interstitial has been loaded and is ready to be displayed by listening to the INTERSTITIAL_LOADED event.

Here is sample code showing the two-step process for showing the interstitial ad:

...
// Register listener for INTERSTITIAL_LOADED event
YaftaMobile.addEventListener(AdEvent.INTERSTITIAL_LOADED,onInterstitialLoaded);
...
// Request an interstitial ad
YaftaMobile.loadInterstitial();
.....
// Show the interstitial ad
protected function onInterstitialLoaded(ev:AdEvent):void{
    YaftaMobile.showInterstitial();
}

Listening to ad events

The YaftaMobile SDK emits events that let you know what happens during the ad life-cycle. To listen to ad events, you need to call the addEventListener(type:String, listener:Function) method where

  • type: is the name of the event to listen to
  • listener: is a callback function that is triggered when the event is fired.

The available ad events to listen to are listed below:


//Fired when an ad is successfully loaded.
public static const AD_LOADED:String = "onAdLoaded";

//Fired when an ad is clicked.
public static const AD_CLICKED:String = "onAdClicked";

//Fired when a failure occurred during ad loading.
public static const AD_ERROR:String = "onAdError";

//Fired when an interstitial ad is loaded.
public static const INTERSTITIAL_LOADED:String = "onInterstitialLoaded";

//Fired when an interstitial ad is clicked.
public static const INTERSTITIAL_CLICKED:String ="onInterstitialClicked";

//Fired when a failure occurred during interstitial ad loading.
public static const INTERSTITIAL_ERROR:String ="onInterstitialError";

//Fired when an interstitial ad is closed.
public static const INTERSTITIAL_DISMISSED:String ="onInterstitialDismissed";

Testing the Integration

The SDK Integration can be tested by enabling test mode to verify that the set up SDK side has been completed correctly. You can enable test mode using the setTestMode(boolean testMode) method

Use the following to enable test mode:

YaftaMobile.setTestMode(true);