MoPub SDK Initialization

The MoPub 5.0 SDK introduces a new API for initialization called MoPub.initializeSdk(). This API is required for a number of new functionalities, including GDPR consent mechanisms and rewarded video. If you have been using MoPubRewardedVideos.initializeRewardedVideo(), it is now part of the new initialization, so make sure to switch to the new API.

Instructions

  1. In your Activity’s onCreate() (or equivalent), instantiate an SdkConfiguration via a Builder with any valid ad unit ID from your app, your mediation settings (optional), and/or a list of mediated rewarded video adapters (optional).
  2. Call MoPub.initializeSdk() and pass in a Context (recommended to be of an Activity type), the SdkConfiguration object, and an SdkInitializationListener object.

Note: Ensure to only request ads once the SDK initialization has completed.

Example

// A list of rewarded video adapters to initialize
List<String> networksToInit = new ArrayList<String>();
networksToInit.add("com.mopub.mobileads.VungleRewardedVideo");

SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder("AD_UNIT_ID")
                                                        .withMediationSettings("MEDIATION_SETTINGS")
                                                        .withNetworksToInit(networksToInit)
                                                        .build();

MoPub.initializeSdk(this, sdkConfiguration, initSdkListener());

private SdkInitializationListener initSdkListener() {
   return new SdkInitializationListener() {
       @Override
       public void onInitializationFinished() {
           /* MoPub SDK initialized. 
           Check if you should show the consent dialog here, and make your ad requests. */
       }
   };
}

Last updated June 05, 2018

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2018 MoPub Inc.