Appnext Android SDK - Banners ad unit

Ad Unit Integration


SDK Installation

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

Step 1 – Initialize the SDK

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



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

Step 2: Add the BannerView to the layout XML


Available sizes for the bannerSize

Banner NameBanner Size

Banner Sizes

Make sure to provide a valid Appnext placement id for the placementId field

You can also create the view via the code itself:

BannerView banner = new BannerView(this);
  • Make sure to make the banner available in the view hierarchy
  • Make sure to set the Appnext placement id once, per each banner, using either the layout xml or by using the code (but not both)

Step 3: Load the Banner

BannerView bannerView = (BannerView) findViewById(;
bannerView.loadAd(new BannerAdRequest());

Step 4: Configure the BannerAdRequest (Optional)

By default, the banner settings will be loaded with pre-defined settings. You can change these settings by defining the BannerAdRequest object

Setters that are relevant to all banner sizes:

  • setCategories - String. Set preferred ad categories
  • setSpecificCategories - Set specific ad categories
  • setPostback - String. Postback parameters that will be posted to your server after user installed an app (make sure to encode the values)

Setters that are relevant only to the MEDIUM_RECTANGLE banner size:

  • setCreativeType - The MEDIUM_RECTANGLE size can show video in addition to static creative. When video is in use, the file will be streamed (default value is ALL - managed by Appnext)
    • BannerAdRequest.TYPE_ALL
    • BannerAdRequest.TYPE_VIDEO
    • BannerAdRequest.TYPE_STATIC
  • setAutoPlay - Boolean. When a video is set as the creative, this setter defining if the video will auto play or not (default value is false)
  • setMute - Boolean. When a video is set as the creative, this setter is defining if the video will start on muted volume or not. Un-mute/Mute button is located on the video creative. (default value is true - video is muted)
  • setVideoLength - When a video is set as the creative, this setter is defining the preferred length of the video. (default value is SHORT)
    • BannerAdRequest.VIDEO_LENGTH_SHORT - Up to 15 seconds long videos
    • BannerAdRequest.VIDEO_LENGTH_LONG - 20-60 seconds long videos
// All sizes example
BannerAdRequest banner_request = new BannerAdRequest();
       .setCategories("category1, category2")
       .setPostback("Postback string");
// ...
// MEDIUM_RECTANGLE size example
BannerAdRequest banner_request = new BannerAdRequest();
  .setCategories("category1, category2")
  .setSpecificCategories("category1, category2")
  .setPostback("Postback string")
// ...

Step 5: Callbacks (Optional)

You can receive client-side callback from the banner by using the “BannerListener” object

bannerView.setBannerListener(new BannerListener() {
   public void onError(AppnextError error) {

   public void onAdLoaded(String s,AppnextAdCreativeType creativeType) {

   public void adImpression() {

   public void onAdClicked() {
  • onAdLoaded(String BannerID) - The banner was successfully loaded, and its ready to be shown to the user (String s = banner ID)
  • AdImpression - The banner was viewed by the user, and an impression was reported to Appnext
  • onAdClicked - The banner was clicked by the user
  • onError - An error has occurred. The following errors codes are passed in the onError callback.
public void onError(AppnextError error) {
   switch (error) {
       case BannersError.CONNECTION_ERROR:
           Log.v("appnext", "client connection error");
       case BannersError.NO_MARKET:
           Log.v("appnext", "couldn't open a valid market")
       case BannersError.TIMEOUT:
           Log.v("appnext", "connection time out client")
       case BannersError.NO_ADS:
           Log.v("appnext", "server - no ads");
			case BannersError.INTERNAL_ERROR:
	    		 Log.v("appnext", "Internal error");
           Log.v("appnext", "other error");

Step 6: Finalize Appnext

Add the following code when you destroy your Activity

public void onDestroy() {

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]