Interstitial

Appnext Android SDK - Interstitial ad unit

Ad Unit Integration

📘

SDK Installation

Make sure to Install the SDK in your Android Studio project as described here

Step 1: Initializing the SDK

Initialize the SDK whenever your app is loaded. Add the following code to your app's main activity

Appnext.init(context);

Step 2: Defining a new Ad

Make sure to set your app's placement ID in the constructor of this class.

Interstitial interstitial_Ad = new Interstitial(this, ADD_HERE_YOUR_PLACEMENT_ID);

📘

New! Get the predicted ECPM value before loading the ad. Check out Appnext solution for in-app header bidding here.

Step 3: Loading an Ad

interstitial_Ad.loadAd();

Step 4: Showing the Ad

interstitial_Ad.showAd();

Step 5: Callbacks (Optional)

In order to receive client-side callbacks, import the following references:

import com.appnext.core.callbacks.OnAdLoaded;
import com.appnext.core.callbacks.OnAdOpened;
import com.appnext.core.callbacks.OnAdClicked;
import com.appnext.core.callbacks.OnAdClosed;
import com.appnext.core.callbacks.OnAdError;

Receive event callbacks from the SDK:

// Get callback for ad loaded
interstitial_Ad.setOnAdLoadedCallback(new OnAdLoaded() {
   @Override
   public void adLoaded(String bannerId, AppnextAdCreativeType creativeType) {
      
   }
});// Get callback for ad opened
interstitial_Ad.setOnAdOpenedCallback(new OnAdOpened() {
   @Override
   public void adOpened() {
      
   }
});// Get callback for ad clicked
interstitial_Ad.setOnAdClickedCallback(new OnAdClicked() {
   @Override
   public void adClicked() {
      
   }
});// Get callback for ad closed
interstitial_Ad.setOnAdClosedCallback(new OnAdClosed() {
   @Override
   public void onAdClosed() {
      
   }
});// Get callback for ad error
interstitial_Ad.setOnAdErrorCallback(new OnAdError() {
   @Override
   public void adError(String error) {
      
   }
});

The possible errors we pass in the adError callback are (AdsError):
CONNECTION_ERROR
SLOW_CONNECTION
AD_NOT_READY
NO_ADS
INTERNAL_ERROR
NO_MARKET
TIMEOUT

Example:

interstitial_Ad.setOnAdErrorCallback(new OnAdError() {
   @Override
   public void adError(String error) {
      switch (error){
         case AdsError.NO_ADS:
            Log.v("appnext", "no ads");
            break;
         case AdsError.CONNECTION_ERROR:
            Log.v("appnext", "connection problem");
            break;
         default:
            Log.v("appnext", "other error");
      }
   }
});

Advanced Settings

Custom Configuration

By default, the Interstitial configuration will be loaded from Appnext's server. You can change the configuration directly by config or through the setter function.

Using Config

In order to use custom configuration, import the following class:

import com.appnext.ads.interstitial.InterstitialConfig;

Define the Interstitial configuration instance:

InterstitialConfig config = new InterstitialConfig();

Examples:

InterstitialConfig config = new InterstitialConfig();
config.setButtonText("Install");
config.setButtonColor("#6AB344");
config.setCategories("category1,category2");
config.setSpecificCategories("category1,category2")
config.setPostback("postback");
config.setAutoPlay(true);
config.setMute(false);
config.setCreativeType(Interstitial.TYPE_MANAGED);
config.setOrientation(Interstitial.ORIENTATION_AUTO);// Or set the property directly:
config.buttonText = "Install";
config.buttonColor = "#6AB344";
config.categories = "category1,category2";
config.postback = "postback";
config.autoPlay = true;
config.mute = false;
config.backButtonCanClose = false;
config.creativeType = Interstitial.TYPE_MANAGED;
config.orientation = Interstitial.ORIENTATION_AUTO;Interstitial interstitial_Ad = new Interstitial(this, placementID, config);

Using Setters:

Interstitial interstitial_Ad = new Interstitial(this, placementID); 
interstitial_Ad.setButtonText("Install");
interstitial_Ad.setButtonColor("#6AB344");
interstitial_Ad.setCategories("category1,category2");
interstitial_Ad.setSpecificCategories("category1,category2")
interstitial_Ad.setPostback("postback");
interstitial_Ad.setAutoPlay(true);
interstitial_Ad.setMute(false);
interstitial_Ad.setCreativeType(Interstitial.TYPE_MANAGED);
interstitial_Ad.setOrientation(Interstitial.ORIENTATION_AUTO);
interstitial_Ad.setBackButtonCanClose(false);

List of configuration options:

Button Text:
The install button's text (default is "Install")

Button Color:
The install button's color - a 6 hex chars starting with # (default is "#6AB344")

Category:
Set preferred ad categories

Install Postback:
Postback parameters that will be posted to your server after user installed an app (make sure to encode the values)

Mute Video:
Mute the video which is played in the Interstitial (default is "false")
true
false

Auto Play Video:
Set video auto-play (default is "true")
true
false

Creative Type:
Set creative type for the main section of the Interstitial (default is "Interstitial.TYPE_MANAGED")
Interstitial.TYPE_MANAGED
Interstitial.TYPE_VIDEO
Interstitial.TYPE_STATIC

Orientation:
Set the preferred orientation if both landscape and portrait are supported by the application (default is ORIENTATION_DEFAULT
Interstitial.ORIENTATION_DEFAULT
Interstitial.ORIENTATION_LANDSCAPE
Interstitial.ORIENTATION_PORTRAIT
Interstitial.ORIENTATION_AUTO

Back Button Can Close:
Set the behavior of the device "Back" button when the interstitial ad unit shows up. The default value is false

  • true - The back button will close the interstitial ad unit
  • false - The back button will not close the interstitial. The user can close the ad unit by clicking the "X" button

Example Project

You can download an example project (Android Studio) from our Github page here.

App Categories

1. Action
2. Adventure
3. Arcade
4. Arcade & Action
5. Board
6. Books & Reference
7. Brain & Puzzle
8. Business
9. Card
10. Cards & Casino
11. Casino
12. Casual
13. Comics
14. Communications
15. Education
16. Educational
17. Entertainment
18. Family
19. Finance
20. Health & Fitness
21. Libraries & Demo
22. Lifestyle
23. Live Wallpaper
24. Media & Video
25. Medical
26. Music
27. Music & Audio
28. News & Magazines
29. Personalization
30. Photography
31. Productivity
32. Puzzle
33. Racing
35. Shopping
36. Simulation
37. Social
38. Sports
39. Sports Games
40. Strategy
41. Tools
42. Travel & Local
43. Trivia
44. Weather
45. Word

Make sure to encode (%20) categories with more than 1 word, example: Travel%20%26%20Local

Integration Support

Should you have any problems integrating the product, log a ticket with us by emailing [email protected]