- Preroll Ads - Android 2.4
- Mediation Partners
- Enabling the Preroll Ad Unit is a Two-Stage Process.
- Load Preroll Ad
- 1. Import Libraries
- 2. Declare a PrerollVideoAd instance. In Activity or Fragment code, declare an instance variable for PrerollVideoAd
- 3. Initialize it.
- 4. Set the Main Content URL and media controller for video player
- 5. Set Ad Request Parameters & Targeting Parameters
- 6. Load it with an ad.
- Show Preroll Ad
- 1. Import Libraries
- 2. Declare an PrerollVideoAd instance. Declare an instance variable for PrerollVideoAd in Activity or Fragment code.
- 3. Initialize it.
- 4. Set the Main Content URL and Ad Request
- 5. Set ad listener to listen various events for Preroll ad
- 6. Add Ad to Layout
- 7. Show your ad
- Sample code
- See below for code snippets in AdListActivity class.
- See below for code snippets in MediaActivity class.
- Event Listeners
5. Set Ad Request Parameters & Targeting Parameters
The information you include in the targeting parameters will be used by various demand systems to display premium ads.
MVDOAdRequest adRequest = new MVDOAdRequest(this); LocationData locationData = new LocationData(this); adRequest.setLocation(locationData.getDeviceLocation()); // It is recommended that you update the below parameter - accurate info is required adRequest.setAppStoreUrl(""); adRequest.setRequester(" "); adRequest.setAppDomain(" "); adRequest.setAppName(" "); adRequest.setCategory(" "); adRequest.setPublisherDomain(" "); // Passing on the following parameter values can result in better targeting and higher yield // For parameters you cannot populate, please comment them out adRequest.setDmaCode("807"); adRequest.setEthnicity("Asian"); adRequest.setPostalCode("94538"); adRequest.setCurrPostal("94539"); adRequest.setDmaCode("807"); adRequest.setAge("27"); adRequest.setMaritalStatus("single"); adRequest.setGender("m"); adRequest.setBirthday("yyyy-mm-dd");
6. Load it with an ad.
LVDOAdSize adSize = new LVDOAdSize(300, 250); preRollVideoAd.loadAd(adRequest,apiKey, adSize, AdListActivity.this, isMainContentFullscreen); Where, adRequest = Request for targeting parameters apiKey = ID for your app - Please contact Vdopia for this adSize = LVDOAdSize(adSize for preroll Ad) AdListActivity.this = PrerollAdListener isMainContentFullscreen = Boolean to show the main content in full screen or not
Please contact Vdopia to obtain your API key. You can contact us at sdk-support@vdopia.com
2. Declare an PrerollVideoAd instance. Declare an instance variable for PrerollVideoAd in Activity or Fragment code.
private PreRollVideoAd preRollVideoAd;
See below for code snippets in AdListActivity class.
public class AdListActivity extends RequestPermissionActivity { private void initializePrerollAd() { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { String apiKey = “”; boolean isMainContentFullscreen = true; LVDOAdSize adSize = new LVDOAdSize(LVDOAd_WIDTH, LVDOAd_HEIGHT); preRollVideoAd = PreRollVideoAd.getInstance(AdListActivity.this); preRollVideoAd.setMediaController(new MediaController(AdListActivity.this)); MVDOAdRequest adRequest = new MVDOAdRequest(AdListActivity.this); LocationData locationData = new LocationData(AdListActivity.this); adRequest.setLocation(locationData.getDeviceLocation()); // It is recommended that you update the below parameter - accurate info is required adRequest.setAppStoreUrl(" "); adRequest.setRequester(" "); adRequest.setAppDomain(" "); adRequest.setAppName(" "); adRequest.setCategory(" "); adRequest.setPublisherDomain(" "); // Passing on the following parameter values can result in better targeting and higher yield // For parameters you cannot populate, please comment them out adRequest.setDmaCode("807"); adRequest.setEthnicity("Asian"); adRequest.setPostalCode("94538"); adRequest.setCurrPostal("94539"); adRequest.setDmaCode("807"); adRequest.setAge("27"); adRequest.setMaritalStatus("single"); adRequest.setGender("m"); adRequest.setBirthday("yyyy-mm-dd"); preRollVideoAd.loadAd(adRequest, apiKey, adSize, AdListActivity.this, isMainContentFullscreen); Log.v(TAG, "Activity : " + this); } } } }
See below for code snippets in MediaActivity class.
public class MediaActivity extends RequestPermissionActivity implements PrerollAdListener { private static final String TAG = "MediaActivity"; private RelativeLayout mAdLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_media); mAdLayout = (RelativeLayout) findViewById(R.id.adLayout); // Permission handling code for Android 6.0 and Above super.requestAppPermissions(mPermissions, R.string.runtime_permissions, REQUEST_PERMISSIONS); } @Override public void onPermissionsGranted(int requestCode) { showPrerollAd(); } private void showPrerollAd() { preRollVideoAd = PreRollVideoAd.getInstance(this); String contentVideo = "http://cdn.vdopia.com/files/happy.mp4"; ViewGroup parent = (ViewGroup) preRollVideoAd.getParent(); if (parent != null) { parent.removeAllViews(); } mAdLayout.addView(preRollVideoAd); preRollVideoAd.setPrerollAdListener(this); preRollVideoAd.showAd(); } @Override public void onPrerollAdLoaded(View prerollAd) { Log.d(TAG, "PreRoll Video Ad onPrerollAdLoaded"); } @Override public void onPrerollAdFailed(View prerollAd, LVDOAdRequest.LVDOErrorCode errorCode) { Log.d(TAG, "PreRoll Video Ad onPrerollAdFailed"); } @Override public void onPrerollAdClicked(View prerollAd) { Log.d(TAG, "PreRoll Video Ad onPrerollAdClicked"); } @Override public void onPrerollAdCompleted(View prerollAd) { Log.d(TAG, "PreRoll Video Ad onPrerollAdCompleted"); } @Override public void onPrepareMainContent(MediaPlayer player) { Log.d(TAG, "PreRoll Video onPrepareMainContent"); } @Override public void onErrorMainContent(MediaPlayer player, int code) { Log.d(TAG, "PreRoll Video onErrorMainContent : " + code); setContentVisibility(); } @Override public void onCompleteMainContent(MediaPlayer player) { Log.d(TAG, "PreRoll Video onCompleteMainContent"); setContentVisibility(); } private void setContentVisibility() { MediaActivity.this.finish(); } }
Event Listeners
You may optionally track ad lifecycle events like request failures or “click-through” by implementing com.vdopia.ads.mp. This interface may be implemented by your activity or any other object.
// called when an ad is loaded public void onPrerollAdLoaded(View prerollAd); // called when there is no ad Public void onPrerollAdFailed(View prerollAd,LVDOAdRequest.LVDOErrorCode errorCode ); // called when an ad is clicked public void onPrerollAdClicked(View prerollAd); // called when an ad is completed public void onPrerollAdCompleted(View prerollAd); // called when the main content is prepared and ready to play public void onPrepareMainContent(MediaPlayer player); // called when an error occurred while main content was playing public void onErrorMainContent(MediaPlayer player, int code); // called when playing of the main content is completed public void onCompleteMainContent(MediaPlayer player);
Let’s get started! Here are steps for integration
1. Add SDK to Android App as Compiled .aar (Gradle project)
To add the Vdopia SDK as an .aar in your project, the SDK from download section, and then copy the .aar to your application library directory.