Adding XappAds to your Project

Maven and Gradle

In your build.gradle, add the link to our maven repository and add XappAds as a dependency:

repositories {
    maven { url "" }

dependencies {
    compile ('com.xappmedia:xapp-ads:3.11.6@aar') {
     transitive = true

Alternate Methods

If you use another method to import dependencies, let us know as we would like to support it.

AndroidManifest.xml Modifications


Add the following permissions, typically right before the <Application> tag:

<!--//BLUETOOTH - Necessary for reporting users audioroute.-->
<uses-permission android:name="android.permission.BLUETOOTH" />
<!--//ACCESS_NETWORK_STATE - Necessary for network optimization and diagnostics.-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--//INTERNET - Necessary for HTTP access-->
<uses-permission android:name="android.permission.INTERNET" />
<!--//RECORD_AUDIO - Necessary for performing voice recognition-->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- Optional -->
<!--//CALL_PHONE - Necessary to enable "Call Now" actions-->
<!--<uses-permission android:name="android.permission.CALL_PHONE" /> -->


Add the following two lines to your AndroidManifest.xml within the <Application> tag:

// allows us to launch the activity for a full screen interstitial.
<activity android:name="xappmedia.sdk.PlayAdActivity"
// allows us to launch an in-app browser to handle touched ads, and certain ad actions.
<activity android:name="xappmedia.sdk.inappbrowser.WebViewActivity"></activity>

Basic Usage

Implement the XappAdsListener

Add import statements, implements XappAdsListener after your class name, and override all of the XappAdsListener methods in your activity.

A simple interaction is as follows:

import android.util.Log;

import xappmedia.sdk.AdRequest;
import xappmedia.sdk.Advertisement;
import xappmedia.sdk.XappAds;
import xappmedia.sdk.XappAdsListener;
import xappmedia.sdk.model.AdResult;
import xappmedia.sdk.model.Error;

public class XappAdsAdapter extends Activity implements XappAdsListener {

    String TAG = "XAPP";
    XappAds xappAds;

    public void onCreate(Bundle savedInstanceState) {


      xappAds = new XappAds();
      xappAds.start(<yourAPIKey>, <yourAPPKey>, userData /** or null */, location /** or null */, <yourContext>, <yourXappAdsListener>);


     * XappAds Listener Methods
    public void onXappAdsStarted () {
        //Request an ad once XappAds has been initialized
        AdRequest adRequest = new AdRequest();

    public void onXappAdsFailed(Error error) {
        Log.e(TAG, "XappAds failed: " + error.getLocalizedMessage());

    public void onXappAdsTerminated() {
        Log.d(TAG, "XappAds terminated");

    public void onAdRequestFailed(AdRequest adRequest, Error error) {
        Log.e(TAG, "Ad request failed " + error.getLocalizedMessage());

    public void onAdRequestCompleted (final Advertisement advertisement) {
        Log.d(TAG, "Ad received");
        //Plays the ad as a full-screen interstitial


    public void onAdStarted(Advertisement advertisement) {
        Log.d(TAG, "Ad started");

    public void onAdCompleted(AdResult adResult) {
        Log.d(TAG, "Ad Complete");

    public void onAdFailed(Error error) {
        Log.e(TAG, "Ad failed " + error.getLocalizedMessage());
        //Failed to get audioFocus or ad failed to play for some other reason described in the error message
//    ...

Start a Session

The API Key and APP key will be provided by your contact person at XappMedia.

 xappAds = new XappAds();
 xappAds.start(<yourAPIKey, <yourAPPKey>, userData /** or null */, location /** or null */, <yourContext>, <yourXappAdsListener>);

The last parameter to the start call is the instance that implements XappAdsListener, which is assumed to be the calling class. Wait for XappAdsListener method onXappAdsStarted to request an ad.

Request an Ad

Request an ad:

//Request an ad once XappAds has been initialized
AdRequest adRequest = new AdRequest();

The XappAdsListener method onAdRequestCompleted will be called when the ad is ready for playback.

Play the Ad

Once you receive the ad, it is ready to play. You can play the ad in three different ways; full-screen interstitial, in-tuner tile, or audio only.

//Play the ad as a full-screen interstitial

//Play the ad as an in-tuner tile, where adView is a reference to a AdView
xappAds.playAsInTuner(adView, advertisement);

//Play the ad as audio only

Request Record Permission

Since the introduction of Android Marshmallow (API 23), applications are no longer automatically granted the permissions they request on install. If you are building for API level 23 and up, to serve ads that require microphone permission you will need to request the record permission. The Permissions API provides an easy way to request the permission from the user. For more detailed information see the Permissions API guide or see the example project.

Add the activity to your AndroidManifest.xml:


Then request the permission:

ArrayList<Permission> collection = new ArrayList<>();

        .keys(apiKey, appKey)
        .startActivity(getActivity(), REQUEST_PERMISSIONS);

Then the Activity will present a prompt with the given rationale asking the user for the permission. If the user accepts, then the Android system prompt will be displayed to actually grant the permissions. The Activity will immediately return if all permissions have already been granted previously.

Important Notes

Duplicate files copied in APK META-INF/LICENSE Error

If you get the following error:

Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/LICENSE
  	File 1: /Users/user/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.4.3/4cb3dbb0c2f75b51aa7543c53252989785a0c609/jackson-core-2.4.3.jar
  	File 2: /Users/user/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.4.3/4cb3dbb0c2f75b51aa7543c53252989785a0c609/jackson-core-2.4.3.jar

Please add to your android namespace to the module’s build.gradle file:

packagingOptions {
    exclude 'META-INF/NOTICE' // will not include NOTICE file
    exclude 'META-INF/LICENSE' // will not include LICENSE file

Passing a Context

It is important that the Context and XappAdsListener provided are fresh when you use the SDK. If either of these would be destroyed during normal application lifecycle, you must currently:

  1. Call xappAds.terminate(),
  2. Create a new instance of XappAds
  3. Call xappAds.start() with a fresh context and listener.

In the above example, this would need to occur any time:

  1. You or someone else calls finish() on the activity which provides the context.
  2. During the default BackPress implementation (which can trigger an onDestroy() call)

You can move the XappAds SDK behind a service, and update the context when refreshing the SDK, but this is beyond the scope of this document.