Early Access - Get Started with Vungle - Android or Amazon SDK v. 6.5.0

Before You Begin

Requirements

  • Android 4.0 (Ice Cream Sandwich - API version 14 and above
  • Amazon OS 5.4 and above
  • In-Feed and MREC ads requires API version 16 and above
  • Migrated to AndroidX on Android SDK 6.5.0

Java Doc

Sample App

Step 1. Include the Vungle SDK in Your Project

The Vungle SDK is available in two ways: as an AAR via Maven, or JAR integration.

Option 1. Gradle Integration

Open the project-level build.gradle, and ensure that the JCenter details are as below.

allprojects {
  repositories {
    maven {
      url "https://jitpack.io"
    }
  }
}

Open the app-level build.gradle file for your app, and add compile dependencies in the dependencies section.

buildscript {
  repositories {
    jcenter()
  }
}

dependencies { 
  // Vungle SDK
  implementation 'com.github.vungle:vungle-android-sdk:6.5.0'
 
  implementation "androidx.core:core:1.1.0"
  implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.0.0"

  // When appcompat is being used, core and localbroadcastmanager are the dependencies
  // that is getting included
  // implementation 'androidx.appcompat:appcompat:1.1.0'

  // Recommended for SDK to be able to get Android Advertising ID
  implementation 'com.google.android.gms:play-services-basement:17.1.1'
  implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
}

If you include the Vungle SDK via Maven, you can skip to "Step 2. Import the Vungle SDK."

Option 2. JAR/AAR Integration

  1. Download Vungle SDK v. 6 , unzip it, go to the libs folder, copy all the jars and add them to your project libs folder.
    vungle-android-sdk-6.5.0.jar
    converter-gson-2.5.0.jar
    gson-2.8.2.jar
    logging-interceptor-3.12.0.jar
    okhttp-3.12.0.jar
    okio-1.15.0.jar
    retrofit-2.5.0.jar
    androidx-vng-moat-mobile-app-kit-2.5.1.jar
    Note : This zip file contains SDK as a .jar as well as an .aar.  Use only one of these depending on jar/aar integration.
    In case if you are using remote JCenter gradle integration, this zip file and its contents are not needed.
  2. Open the project-level build.gradle, and update the repositories section:
    allprojects {
        repositories {
            jcenter()
       }
    }
  3. Open the app-level build.gradle file for your app, and add other dependencies in the dependencies section. If you are using .aar instead of .jar, you do not need to include VNG-moat-mobile-app-kit-2.5.1.jar since .aar is already packaged with this library.
    dependencies {
      // Vungle SDK
      implementation files('libs/vungle-android-sdk-6.5.0.jar')
    
      // Required Third-party Dependencies
      implementation files('libs/converter-gson-2.5.0.jar')
      implementation files('libs/gson-2.8.2.jar')
      implementation files('libs/logging-interceptor-3.12.0.jar')
      implementation files('libs/okhttp-3.12.0.jar')
      implementation files('libs/okio-1.15.0.jar')
      implementation files('libs/retrofit-2.5.0.jar')
      implementation files('libs/androidx-vng-moat-mobile-app-kit-2.5.1.jar') // Exclude when using AAR
    
      implementation "androidx.core:core:1.1.0"
      implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.0.0"
    
      // When appcompat is being used, core and localbroadcastmanager are the dependencies
      // that is getting included
      // implementation 'androidx.appcompat:appcompat:1.1.0'
    
      // Recommended for SDK to be able to get Android Advertising ID
      implementation 'com.google.android.gms:play-services-basement:17.0.0'
      implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    }
    
  4. Update AndroidManifest.xml by adding the following lines to your AndroidManifest.xml and assigning the application item name to your application class name for multidex:
    <!--Required Permissions-->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <!--Recommended Permissions-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
        
    <!--Vungle Activities-->
    <activity
        android:name="com.vungle.warren.ui.VungleActivity"
        android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
        android:launchMode="singleTop"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
    
    <activity
        android:name="com.vungle.warren.ui.VungleFlexViewActivity"
        android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
        android:launchMode="singleTop"
        android:hardwareAccelerated="true"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    
    <receiver
        android:name="com.vungle.warren.NetworkProviderReceiver"
        android:enabled="false">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>

Step 2. Import the Vungle SDK

import com.vungle.warren.Vungle;
import com.vungle.warren.AdConfig;              // Custom ad configurations
import com.vungle.warren.InitCallback;          // Initialization callback
import com.vungle.warren.LoadAdCallback;        // Load ad callback
import com.vungle.warren.PlayAdCallback;        // Play ad callback
import com.vungle.warren.VungleNativeAd;        // In-Feed and MREC ad
import com.vungle.warren.Banners;               // Banner ad
import com.vungle.warren.VungleBanner;          // Banner ad
import com.vungle.warren.Vungle.Consent;        // GDPR consent
import com.vungle.warren.VungleSettings         // Minimum disk space
import com.vungle.warren.error.VungleException  // onError message

Step 3. Initialize the Vungle SDK

Starting with v6.3.12, we have removed the requirement for passing all placement reference ID to be used in the session during the initialization. SDK initialization can now be done without passing Collection of placement reference ID and all active placements for the application ID will be usable to play and load ad. You can still use the legacy API, but it is planned to be deprecated in the future.

// New v6 API
public static void init(@NonNull String appId,
                        @NonNull Context context,
                        @NonNull InitCallback callback)

// New since v6.4.11 API with optional minimum disk space configuration
public static void init(@NonNull final String appId,
                        @NonNull final Context context,
                        @NonNull final InitCallback callback,
                        @NonNull final VungleSettings settings)

// Legacy v6 API
@Deprecated
public static void init(@NonNull final Collection placements,
                        @NonNull String appId,
                        @NonNull Context context,
                        @NonNull InitCallback callback) 

The initialization method takes the following parameters:

  • Vungle Application ID
  • Application context
  • InitCallback
    • onSuccess: notifies when SDK has successfully initialized
    • onError: notifies when the initialization has failed
      • Throws IllegalArgumentException if InitCallback is null.
      • Starting with v6.5.0, throws VungleException if required arguments are missing or invalid. For v6.4.11 and below, Throwable object was passed.
    • onAutoCacheAdAvailable: notifies when the auto-cached placement has an ad available to play
  • VungleSettings (optional)
    • Specify minimum space available on device for SDK initialization and operation

For all placements, loadAd must be explicitly issued as described in “Step 5. Load an Ad.”

Vungle.init(appId, getApplicationContext(), new InitCallback() {
    @Override
    public void onSuccess() {
        // Initialization has succeeded and SDK is ready to load an ad or play one if there
        // is one pre-cached already
    }

    @Override
    public void onError(VungleException exception) {
        // Initialization error occurred - exception.getLocalizedMessage() contains error message
    }

    @Override
    public void onAutoCacheAdAvailable(String placementId) {
        // Callback to notify when an ad becomes available for the cache optimized placement
        // NOTE: This callback works only for the cache optimized placement. Otherwise, please use
        // LoadAdCallback with loadAd API for loading placements.
    }
};

You can check whether Vungle SDK is initialized anytime by calling the isInitialized method:

public static boolean isInitialized()

Step 4. Event Listener

Implement LoadAdCallback for ad load events and PlayAdCallback for ad play events now if you want to use generic callback for all events. Otherwise, skip to “Step 5. Load an Ad” to implement inline callbacks.

Note: Starting with v6.5.0, onError callback for PlayAdCallback and LoadAdCallback passes VungleException compared to a Throwable object for v6.4.11 and below.

// Implement LoadAdCallback
private final LoadAdCallback vungleLoadAdCallback = new LoadAdCallback() { 
  @Override
  public void onAdLoad(String placementReferenceId) { 
    // Placement reference ID for the placement to load ad assets 
  } 

  @Override 
  public void onError(String placementReferenceId, VungleException exception) { 
    // Placement reference ID for the placement that failed to download ad assets 
    // VungleException contains error code and message 
    }
};
// Implement PlayAdCallback
private final PlayAdCallback vunglePlayAdCallback = new PlayAdCallback() { 
  @Override 
  public void onAdStart(String placementReferenceId) { 
    // Placement reference ID for the placement to be played 
  } 

  @Override 
  public void onAdEnd(String placementReferenceId, boolean completed, boolean isCTAClicked) { 
    // Placement reference ID for the placement that has completed ad experience 
    // completed has value of true or false to notify whether video was 
    // watched for 80% or more 
    // isCTAClkcked has value of true or false to indicate whether download button 
    // of an ad has been clicked by the user 
  }

  @Override 
  public void onError(String placementReferenceId, VungleException exception) { 
    // Placement reference ID for the placement that failed to play an ad 
    // VungleException contains error code and message
  }
};

Step 5. Load an Ad

The LoadAdCallback will be notified about the load state for the call to which it was assigned. The SDK only references this callback and does not store it anywhere; it is the responsibility of the caller to ensure that the callback is managed properly.

public static void loadAd(@NonNull final String id, @Nullable LoadAdCallback callback)
// Load Ad Implementation
if (Vungle.isInitialized()) {
  Vungle.loadAd("PLACEMENT_ID", new LoadAdCallback() {
    @Override
    public void onAdLoad(String placementReferenceId) { }

    @Override
    public void onError(String placementReferenceId, VungleException exception) { }
  });
}

Step 6. Check Ad Availability

Use static method canPlayAdmethod to check if there is an ad available to play for the placement before invoking the playAd method 

public static boolean canPlayAd(@NonNull String id)

Step 7. Play an Ad

To play an ad, invoke the playAd method, with the placement reference ID, optional AdConfig (null if not being used), and a PlayAdCallback event listener, which will be notified of success or errors during ad playback.

public static void playAd(@NonNull final String id, final AdConfig settings, @Nullable final PlayAdCallback listener)

You should always check ad availability by calling the canPlayAd method before invoking the playAd method. You must also make sure that an additional playAd is not issued before your receive an onAdEnd or an onError callback from the initial playAd call, because the ad will not render properly if playAd is repeatedly called in quick succession.

if (Vungle.canPlayAd("PLACEMENT_ID")) { 
  Vungle.playAd("PLACEMENT_ID", null, new PlayAdCallback() { 
    @Override public void onAdStart(String placementReferenceId) { } 
    @Override public void onAdEnd(String placementReferenceId, boolean completed, boolean isCTAClicked) { } 
    @Override public void onError(String placementReferenceId, VungleException exception) { } 
  });
}

Re-initialize SDK when onError occurs

On rare occurrences, resources can become limited, causing the system to deallocate either part of the Vungle SDK, or some of the third-party dependencies our SDK requires. In such cases, LoadAdCallback and PlayAdCallback fire an onError callback with a VungleException object with a code VungleException.VUNGLE_NOT_INTIALIZED. This indicates that the Vungle SDK is in an inoperable state and must be re-initialized.

if (e.getExceptionCode() == VungleException.VUNGLE_NOT_INTIALIZED) {
  // Re-initialize Vungle SDK
}

Native Ads

In-Feed Ads

The In-Feed ad format does not require a full screen to display; instead, the Publisher determines the exact dimensions and location of the ad container within their app. These ad containers can be in collection views or table/list views.

Loading an In-Feed Ads

The Publisher must load an ad for the In-Feed container. Loading a In-Feed ad is same as loading a full-screen or interstitial ad; however, the placement must be configured to support In-Feed.

Displaying an In-Feed Ad

Displaying In-Feed ads differs from displaying full-screen ads. With In-Feed ads, you must first create a container for the ad. This container is a Layout. You can place said RelativeLayout anywhere on the screen. The ad will scale to any size of container, but keep in mind that very low resolution will make ads less visible. You must then call the Vungle.getNativeAd to get the In-Feed ad object and call the addView function to associate the container with the In-Feed ad.

private RelativeLayout flexfeedContainer = findViewById(...);

VungleNativeAd vungleNativeAd = Vungle.getNativeAd("INFEED_ID", new AdConfig(), vunglePlayAdCallback);

if (vungleNativeAd != null) { View nativeAdView = vungleNativeAd.renderNativeView(); flexfeedContainer.addView(nativeAdView); }

Note: There was a change in getNativeAd API starting from version 6.5.0. If you are using version 6.4.11 or below, there is no need to pass AdConfig object and you would need placement reference ID and VunglePlayAdCallback only.

Vungle.getNativeAd("INFEED_ID", vunglePlayAdCallback);

Closing an In-Feed Ad

Because the In-Feed ad view has been added to your container view, it must also be removed in case the ad view disappears from the screen, the activity or fragment is destroyed, or the parent view container is recycled or destroyed. Without closing the ad, attempting to play another In-Feed ad will cause unexpected behavior in your app. Please invoke finishDisplayingAd to end ad experience and we recommend that you remove the view onAdEnd event.

private VungleNativeAd vungleNativeAd;

// Calling finishDisplayingAd when you want to finish displaying In-Feed Ad
// will trigger onAdEnd and will tell you when you can remove the child
// In-Feed view container
vungleNativeAd.finishDisplayingAd();

// And removing empty ad view from container
@Override 
public void onAdEnd(String id, boolean completed) {
    …
    parentView.removeView(nativeAdView);
    vungleNativeAd = null;
    …
}

Attaching and Detaching the State of an In-Feed Ad

If the user scrolls to a point where the video ad is no longer visible on the screen, the Publisher must pause the video, and resume it when it is again visible. To control the pause and resume states, call setAdVisibility from the VungleNativeAd instance, and set it to ‘true’ when the video is visible and to ‘false’ when the video goes off screen. The setAdVisibility is not to be confused with View visibility: this setter informs Vungle SDK whether the Native ad view is visible or not, and depending on it, the SDK pauses/resumes video playback.

To Pause an In-Feed Ad

vungleNativeAd.setAdVisibility(false);

To Resume an In-Feed Ad

vungleNativeAd.setAdVisibility(true);

MREC Ads

From SDK version 6.4.11 and above, Vungle supports MREC video ads, which does not require full screen view, similar to In-Feed ad. The container size to render MREC ad is 300 by 250 which is the industry standard. MREC video ads can be set anywhere on the screen and the user can continue using the app while the ad is being played.

Loading an MREC Ad

Loading an MREC ad is same as loading a full screen ad. However, the placement must be configured to support MREC feed. Please contact your Vungle account manager to enable MREC for a placement.  

Displaying an MREC Ad

Since the view size is fixed, the container which is used to display MREC must be specified to be 300dp by 250dp, and the view can be placed anywhere on the screen. This container is a Layout. You can place said RelativeLayout anywhere on the screen. You must then call AdConfig.setAdSize to specify ad size to be AdConfig.AdSize.VUNGLE_MREC and pass this object when calling Vungle.getNativeAd to get the MREC ad object. finally call the addView function to associate the container with the MREC ad. Vungle MREC plays with sound enabled by default but you can use setMuted option set to true to start the video muted.

private RelativeLayout mrecContainer = findViewById(...);

AdConfig adConfig = new AdConfig();
adConfig.setAdSize(AdConfig.AdSize.VUNGLE_MREC);
adConfig.setMuted(true);

VungleNativeAd vungleNativeAd = Vungle.getNativeAd("MREC_ID", adConfig, vunglePlayAdCallback);
View nativeAdView = vungleNativeAd.renderNativeView();
mrecContainer.addView(nativeAdView);

Closing an MREC Ad

Because the MREC ad view has been added to your container view, it must also be removed in case the ad view disappears from the screen, the activity or fragment is destroyed, or the parent view container is recycled or destroyed. Without closing the ad, attempting to play another MREC ad will cause unexpected behaviour in your app. Please invoke finishDisplayingAd to end ad experience and we recommend that you remove the view onAdEnd event.

private VungleNativeAd vungleNativeAd;

// Calling finishDisplayingAd when you want to finish displaying MREC Ad
// will trigger onAdEnd and will tell you when you can remove the child
// MREC view container 
vungleNativeAd.finishDisplayingAd();

// And removing empty ad view from container
@Override 
public void onAdEnd(String id, boolean completed) {
    …
    parentView.removeView(nativeAdView);
    vungleNativeAd = null;
    …
}

Attaching and detaching the state of an MREC Ad

If the user scrolls to a point where the video ad is no longer visible on the screen, the Publisher must pause the video, and resume it when it is again visible. To control the pause and resume states, call setAdVisibility from the VungleNativeAd instance, and set it to ‘true’ when the video is visible and to ‘false’ when the video goes off screen. The setAdVisibility is not to be confused with View visibility: this setter informs Vungle SDK whether the native ad view is visible or not, and depending on it, the SDK pauses/resumes video playback. 

To Pause an MREC Ad

vungleNativeAd.setAdVisibility(false);

To Resume an MREC Ad

vungleNativeAd.setAdVisibility(true);

Banner Ads

Vungle supports Banner video ads starting with SDK version 6.5.0. The container size to render banner ads can be 320x50, 300x50 or 728x90 (for tablets).
Banner ads can be set anywhere on the screen and the user can continue using the app while the ad is being played.

Banner Size

Dimensions

AdConfig.AdSize.BANNER

320x50

AdConfig.AdSize.BANNER_SHORT

300x50

AdConfig.AdSize.BANNER_LEADERBOARD

728x90 (for tablets)

Loading a Banner Ad

Loading a banner ad works different than other ad formats. There is specific Banners API that you use to load, play and check for ad availability. You would need to specify size of the banner that you want to load and SDK will automatically refresh it with the time interval that you configured on the dashboard. The placement must be also configured to support banner feed so please contact your Vungle account manager to enable banner ad for a placement.

Banners.loadBanner("BANNER_ID", AdConfig.AdSize.BANNER, vungleLoadAdCallback);

You can check for banner ad availability by calling canPlayAd method.

Banners.canPlayAd(ad.placementReferenceId, AdConfig.AdSize.BANNER);

Displaying a Banner Ad

Since the view size is fixed, the container which is used to display Banner ads must be specified to be one of the supported sizes 320x50, 300x50 or 728x90 (for tablets), and the view can be placed anywhere on the screen. This container is a LayOut it must have a size equal to or greater than the banner size being used. You can place said LayOut anywhere on the screen. Then you will pass the size of banner you are using Banners API.

Pass this object when calling Banners.loadBanner to specify the size you displaying and use Banners.getBanner to get the Banners ad object. finally call the addView method to associate the container with the Banner ad.

private RelativeLayout bannerContainer = findViewById(...);
// Check for banner ad availability and display
if (Banners.canPlayAd("BANNER_ID", AdConfig.AdSize.BANNER)) {
  VungleBanner vungleBanner = Banners.getBanner("BANNER_ID", AdConfig.AdSize.BANNER, vunglePlayAdCallback);
  bannerContainer.addView(vungleBanner);
}

Closing a Banner Ad

Because the banner ad view has been added to your container view, it must also be removed in case the ad view disappears from the screen, the activity or fragment is destroyed, or the parent view container is recycled or destroyed. Without closing the ad, attempting to play another banner ad will cause unexpected behaviour in your app.

vungleBanner.destroyAd();

Advanced Banner Configuration

For most cases, above integration will be sufficient and VungleBanner will be managed. However, if VungleBanner view is inside a list or RecyclerView, the managed VungleBanner will not work correctly. The moment the user scrolls the ad offscreen and scrolls back, the ad will be finished and no longer there. For such case, we have advanced API to fine control the VungleBanner. Please refer to our main banner integration guide for more information.

Google Play Services (Optional)

Including Google Play Services with your project allows Vungle to provide a more customized ad experience to the end user. Including basement and ads-identifier API’s are optional but recommended. We recommend using version 11.0.1 or higher.

To include Google Play Services, we recommend Google's setup guide. In your app, ensure that the device has a sufficiently updated version of Google Play Services. Vungle SDK optionally utilizes the location and ads API from Google Play Services.

  • google.android.gms:play-services-basement:16.0.0  // Recommended
  • google.android.gms:play-services-ads-identifier:16.0.0  // Required for AAID

Method Count Reduction

Adding Vungle Android SDK v6 to your project will add approximately 700 core Vungle methods, excluding any transitive dependencies. A full integration including third-party libraries is expected to add less than 4000 methods in average. Consider the following suggestions to reduce the total number of methods added to your project.

  • ProGuard: You can enable ProGuard to shrink your project code. It will discard any unused classes at the time of compilation to make the total method count as small as possible. You can enable it by specifying minifyEnabled true in build.gradle for appropriate build type and by providing the rules to keep the classes that is required by your project.
  • Multidex: If you are still above a 65K method count, enabling multiDex may be the only solution provided by Google. You need to configure your project to multiDex only one time, but it will have an impact on build and app startup time.

Proguard

If you are using Proguard, add the following rules to your ProGuard configuration file:

# Vungle
-keep class com.vungle.warren.** { *; }
-keep class com.vungle.warren.downloader.DownloadRequest
-dontwarn com.vungle.warren.error.VungleError$ErrorCode
-dontwarn com.vungle.warren.downloader.DownloadRequest$Status
-keepclassmembers enum com.vungle.warren.** { *; } # Moat SDK -keep class com.moat.** { *; } -dontwarn com.moat.** -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement -keepattributes *Annotation* # Retrofit -keepattributes Signature, InnerClasses -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement -dontwarn javax.annotation.** -dontwarn kotlin.Unit -dontwarn retrofit2.-KotlinExtensions -keepclassmembers,allowshrinking,allowobfuscation interface * { @retrofit2.http.* <methods>; } # Okio+OkHttp -dontwarn okhttp3.** -dontwarn okio.** -dontwarn javax.annotation.** -dontwarn org.conscrypt.** -keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase -keepclassmembers class * extends com.vungle.warren.persistence.Memorable { public <init>(byte[]); }
 

Minimum disk space

Minimum disk space configuration was introduced in v6.4.11 to determine the limits for available space on a user’s device before the Vungle SDK initializes and fetch ads. Default value for setMinimumSpaceForInit is 51 MB and setMinimumSpaceForAd is 50 MB. The size is entered in bytes.

VungleSettings vungleSettings = new VungleSettings.Builder()
    .setMinimumSpaceForInit(51L * 1024L * 1024L)  // 51 MB
    .setMinimumSpaceForAd(50L * 1024L * 1024L)    // 50 MB
    .build();
  
Vungle.init(appId, getApplicationContext(), initCallback, vungleSettings); 

Restrict usage of device ID

For Android SDK version 6.4.11 onwards, publishers can now restrict transmission of Android ID which is used when Google Advertising ID is not available.

// Set true to opt out for Android ID collection by SDK or false (default) to opt in
VungleSettings vungleSettings = new VungleSettings.Builder()
    .setAndroidIdOptOut(true)
    .build();
    
Vungle.init(appId, getApplicationContext(), initCallback, vungleSettings);

Ad Configuration Options

Ad Configuration

You have the option to customize individual ads you play by providing a new adConfig object to playAd. AdConfig is an object and can be null, in which case the ad will play with default configurations; or it can be a non-null with overrides to the AdConfig setter. The following is an example of how to use AdConfig

Vungle.playAd(placementReferenceID, adConfig, vunglePlayAdCallback);

The above uses adConfig object that has customization option configuration and you set the AdConfig object as shown here

AdConfig adConfig = new AdConfig();
adConfig.setAdOrientation(AdConfig.AUTO_ROTATE);
adConfig.setMuted(true);
Vungle.playAd(placementReferenceID, adConfig, vunglePlayAdCallback);

The following table shows all the available AdConfig options.

Option

Description

setBackButtonImmediatelyEnabled

true if back button should be enabled before ad close button appears, false otherwise

setAdOrientation

AdConfig.AUTO_ROTATE if the video ad is supposed to auto-rotate, otherwise AdConfig.LANDSCAPE or AdConfig.PORTRAIT to follow video ad orientation

setMuted

false if the video should start with its audio settings matching those of your enclosing application, true if it should start muted regardless

setOrdinal

Takes an Integer value of ordinal count to track the number of ads that has been played in same session

Note: You may use the same AdConfig object for multiple ads Placement Reference IDs you play.

Customizing Rewarded Ads

The pop-up message dialog for rewarded ads is configurable with setIncentivizedFields method.

public static void setIncentivizedFields(@Nullable String userID, @Nullable String title, @Nullable String body, @Nullable String keepWatching, @Nullable String close)

List of Valid Placements

A helper method that returns Collection of String containing all valid Placement Reference IDs for the current session.

public static Collection getValidPlacements()

GDPR Recommended Implementation Instructions

As of May 25th, the General Data Protection Regulation (GDPR) will be enforced in the European Union. To comply with GDPR, developers have two options.

  • Option 1 (recommended): Publisher controls the GDPR consent process at the user level, then communicates the user’s choice to Vungle. To do this, developers can collect the user’s consent using their own mechanism, and then use Vungle APIs to update or query the user’s consent status. Refer to the GDPR Recommended Implementation Instruction section for details.
  • Option 2: Allow Vungle to handle the requirements. Vungle will display a consent dialog before playing an ad for a European user, and will remember the user’s consent or rejection for subsequent ads.

The updateConsentStatus method (as recommended in Option 1) takes user consent status and consent message version as its parameters.


public static void updateConsentStatus(@NonNull Consent status, @NonNull String consentMessageVersion)

The consent status will specify whether the user has OPTED_IN or OPTED_OUT for the message being displayed by the publisher. The consentMessageVersion indicates publisher controlled consent policy version to allow publisher getting consent again when GDPR policy changes by pooling users by the message version.

// Usage example of GDPR API
// To set the user's consent status to opted in:
Vungle.updateConsentStatus(Vungle.Consent.OPTED_IN, “1.0.0”);

// To set the user's consent status to opted out:
Vungle.updateConsentStatus(Vungle.Consent.OPTED_OUT, “1.0.0”);

// To find out what the user's current consent status is:
// This will return null if the GDPR Consent status has not been set
// Otherwise, it will return Vungle.Consent.OPTED_IN or Vungle.Consent.OPTED_OUT
Vungle.Consent currentStatus = Vungle.getConsentStatus();
String consentMessageVersion = Vungle.getConsentMessageVersion();

Hardware Acceleration

Hardware acceleration Hardware acceleration is enabled by default for your application if your target API level is set to 14 or above. This option must be enabled for the SDK to properly show Dynamic Template, In-Feed and MREC ads. Make sure this option is set to 'true' at application level of your project.

<application android:hardwareAccelerated="true" ...>

Retrieving the SDK Version Number

To programmatically retrieve the SDK version number at runtime (this useful in internal mediation), Vungle provides the following String:

com.vungle.warren.BuildConfig.VERSION_NAME

Debugging Exception Code

InitCallback, PlayAdCallback and LoadAdCallback will have VungleException code when onError callback fires. You can use the code to debug or take actions to correct the issue programmatically.

if (exception.getExceptionCode() == VungleException.VUNGLE_NOT_INTIALIZED) {
  // Call routine to initialize SDK
}
Exception Code Description
CONFIGURATION_ERROR Configuration Error Occurred. Please check your app ID and placement reference IDs, and try again when network connectivity is available.
NO_SERVE Ad server found no advertisements are available for your current bid. Please try again later. Occurrence of this exception is expected behavior.
UNKNOWN_ERROR Unknown Error Occurred. Occurrence of this exception should be rare.
AD_EXPIRED The advertisement in the cache has expired and can no longer be played. Please load another ad.
MISSING_REQUIRED_ARGUMENTS_FOR_INIT Please ensure all parameter for init marked as NonNull are provided, as they are essential for functioning of our SDK.
APPLICATION_CONTEXT_REQUIRED Please provide Application context so our SDK can continue to support our API beyond Activity lifecycle.
OPERATION_ONGOING There is already an ongoing operation for the action you requested. Please wait until the operation finished before starting another.
VUNGLE_NOT_INTIALIZED Vungle is not initialized or no longer initialized. Please call Vungle.init() to reinitialize.
AD_UNABLE_TO_PLAY Unable to play advertisement.
AD_FAILED_TO_DOWNLOAD Advertisement failed to download.
PLACEMENT_NOT_FOUND Placement is not valid.
SERVER_RETRY_ERROR Remote Server responded with http Retry-After, SDK will retry this request.

Configuring Auto Backup for JAR Integration

The ‘Allow backup’ setting is enabled by default for your application for API 23 or above. The backup rule ensures that all application data is backed up for proper operation of Vungle SDK and application itself. If you have not disabled the allow backup setting or specified your own backup rules, you must provide additional .xml rules to define which files in our SDK file system should be excluded from automatic backup. 

Vungle Exclusion Rules

<full-backup-content>
    <exclude domain="file" path="vungle" />
    <exclude domain="file" path="vungle_cache" />
    <exclude domain="external" path="vungle_cache" />
    <exclude domain="database" path="vungle_db" />
    <exclude domain="sharedpref" path="com.vungle.sdk.xml" />
</full-backup-content>

Gradle Integration with Developer Backup Rules

  1. Add Vungle SDK exclusion rules to the existing .xml file that has your app’s own exclusion rules.
  2. Configure fullBackupContent to be replaced on the application level and add the Vungle SDK exclusion rule to the existing .xml.

JAR Integration with developer backup rules

  1. Create a new XML file with Vungle exclusion rules.
  2. Place the .xml file under the res/xml directory.
  3. Add fullBackupContent in the application tag of AndroidManifest.xml with the file name of the .xml file you created above.
    <application
        android:fullBackupContent="@xml/vungle_backup_rule">

Disabling Auto Backup

If backup is not required for your app, you can simply disable it on the application tag:

<application 
    android:allowBackup="false" >
Was this article helpful?

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!