Get Started

Introduction

The YaftaMobile Android SDK makes it easy to integrate high-quality ads into your android apps.

This guide describes how to integrate the YaftaMobile SDK with your Android app.

Download the latest release of YaftaMobile's SDK for Android here

Prerequisites

The YaftaMobile Android SDK requires a run-time of Android 4.0.3 (API Version 15) and up.

The YaftaMobile Android SDK requires the Google Play Services, 4.0 or higher, library to function. This is to comply with the Google Play content guidelines for collecting the advertising identifier. To add the SDK, please follow the official Integration Instructions.

Requirements
 

Step 1: Add the SDK to your Project

To use the YaftaMobile Android SDK, you have two options. You can install it automatically using Gradle's Dependency Management or manually install it by including the SDK source code in your project.



- Install using Gradle

The simplest way to integrate the SDK into your project is by using Gradle’s Dependency.



- Manual Install

If you are not using Gradle, you can download and unzip the Yaftamobile SDK. Copy the JAR file (YaftaMobileAndroidSDK-x.x.x.jar) to the /libs directory of your project and then add it as dependency to your project. As an example, for projects using Eclipse IDE, follow the steps below:

  1. Copy the YaftaMobileAndroidSDK-x.x.x.jar file to your project’s libs folder.
  2. Right-click on YaftaMobileAndroidSDK-x.x.x.jar file and select Build Path > Add to Build Path.

Add JAR to Build Path in Eclipse

To install using Gradle, add this to Module-level /app/build.gradle before dependencies:

repositories {
mavenCentral()
}

 

Then add the compile dependencies: 

dependencies {
implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.google.android.gms:play-services-ads:11.0.4'
implementation 'com.mustamara.android:yaftamobile-android-sdk:3.0.0'
}

Step 2: Add permissions

Making ad requests requires the INTERNET and ACCESS_NETWORK_STATE permissions to be declared in your AndroidManifest.xml file.

These permissions need to be declared outside of the <application…>  tag.

<uses-permission 
android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step 3: Set Your AppID

In order to fetch ads, you must set your AppID. This allows YaftaMobile to track your app impressions and clicks, and associate them with your account.

Open the AndroidManifest.xml file and add a 'Meta Data' item called com.mustmara.yaftamobile.sdk.appid, with a value of your AppID that is shown on the dashboard site.

Within the <application...> tag, add the following:

 <meta-data 
android:name="com.mustamara.yaftamobile.sdk.appid"
android:value="<YOUR-APPID>"
/>

Step 4: Add YaftaMobileBannerView

To retrieve and display banner ad, you will use an instance of YaftaMobileBannerView, which can be created either in code or XML.The easiest way to incorporate banner ad is to simply define your YaftaMobileBannerView as you would any other part of your res/layout/main_layout.xml.

Add the yaftamobile namespace to the root Layout into the xml file in res/layout/:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yaftamobile="http://schemas.android.com/apk/lib/com.mustamara.yaftamobile.sdk"
...

 

Then add the YaftaMobileBannerView to the layout: 

<com.mustamara.yaftamobile.sdk.ads.banner.YaftaMobileBannerView
android:id="@+id/bannerView"
android:layout_width="320dp"
android:layout_height="50dp"
yaftamobile:adSize="S320X50" />

Step 5: Verify SDK Integration

To verify that the SDK has been properly integrated, use the RunMode.TEST to inform the SDK to fetch test ads then call requestAd() method to load and display the ad.

Once you have completed these steps, you can run your application and you should see a test banner displayed on the screen

Place the following code in order to display an ad on the screen:

import com.mustamara.yaftamobile.sdk.*;
import com.mustamara.yaftamobile.sdk.ads.banner.*;
...
public void onCreate(...) {
...


YaftaMobileBannerView bannerView;
bannerView= (YaftaMobileBannerView)findViewById(R.id.bannerView);
AdRequest adRequest=new AdRequest();
adRequest.setRunMode(RunMode.TEST);
bannerView.requestAd(adRequest);

...
}

Advanced Settings



Testing 

During development and testing of the YaftaMobile Android SDK, you should indicate all ad requests are for testing. Test requests will not show up in your metrics.

Note: Ensure that you set the Mode to RunMode.LIVE when distributing the app to users. By default, Mode is set to RunMode.LIVE 



ProGuard Support

If you are building your app using ProGuard, you need to add the following code to your Proguard configuration, so that our SDK will not be obfuscated twice.





Request test ads by setting the test run mode

adRequest.setRunMode(RunMode.TEST);







Add these ProGuard flags to your Proguard configuration file

-keep public class com.mustamara.yaftamobile.sdk.** {*;} 
-keep public interface com.mustamara.yaftamobile.sdk.** {*;}
-dontwarn com.mustamara.yaftamobile.sdk.**
Next Steps
  • See Banner Ads for more settings.
  • Explore our code sample on GitHub which demonstrate how to load an ad.