Interstitial Ads - Android 2.4

Interstitial ads provide full-screen experience, commonly incorporating rich media to offer a higher level of interactivity.
Interstitial ads are typically shown during natural transitions in your app, e.g. after completing a game level, or while waiting for a new view to load



Mediation Partners

Mediation Partners



Integrating Interstitial Ad

Integrating Interstitial Ad



1. Import necessary classes

import com.vdopia.ads.lw.LVDOAdRequest; import com.vdopia.ads.lw.LVDOConstants; import com.vdopia.ads.lw.LVDOInterstitialAd; import com.vdopia.ads.lw.LVDOInterstitialListener;



2. Declare an LVDOInterstitialAd instance variable in the Activity where you want to show the interstitial ad.

private LVDOInterstitialAd mInterstitialAd;

LVDOInterstitialAd provides a listener interface, LVDOInterstitialListener, which you’ll use to stay informed about ad lifecycle events. Make sure your Activity implements LVDOInterstitialListener interface.



3. Instantiate the LVDOInterstitialAd

In your Activity’s onCreate() method, using the activity context, apikey and listener, instantiate the LVDOInterstitialAd. To ensure a smooth experience, you should pre-fetch the ad as soon as your Activity is created.

mInterstitialAd = new LVDOInterstitialAd(this, mApiKey, this);

Where,
this is context,
mApiKey is your SSP API key, and
this is LVDOInterstitialListener.

Please contact Vdopia to obtain your SSP API key. You can contact us at sdk-support@vdopia.com



4. Set Ad Request Parameters & Targeting Parameters

LVDOAdRequest adRequest = new LVDOAdRequest(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");



5. Load the ad.

mInterstitialAd.loadAd(adRequest);



6. Use onInterstitialLoaded (LVDOInterstitialAd ad ) method to check whether the interstitial ad was successfully prefetched.



7. Display the interstitial by calling the show () method.

You can add logic to the other Interstitial lifecycle methods to handle what should happen when your user interacts with the ad.
e.g. resuming your game onInterstitialDismissed(LVDOInterstitialAd ad).



8. Call destroyView() method for the instance variable created for Interstitial ad in your Activity’s onDestroy() method.



Sample Code

public class InterstitialActivity extends Activity implements LVDOInterstitialListener { private static final String TAG = "InterstitialActivity"; private String mApiKey; private LVDOInterstitialAd mInterstitialAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_interstitial); if (getSupportActionBar() != null) { getSupportActionBar().setTitle(getIntent().getStringExtra("title")); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } String mCategory = getIntent().getStringExtra("CATEGORY"); mApiKey = getIntent().getStringExtra(AppConstant.EXTRA_API_KEY); if (mApiKey == null || mApiKey.trim().length() == 0) { mApiKey = ApiKey.getApiKeyCommon(this); } Log.v(TAG, "Api Key..." + mApiKey); loadInterstitial(); final List channelArrayList = new ArrayList<>(); final NewsFeedAdapter adapter = new NewsFeedAdapter(InterstitialActivity.this, channelArrayList); ListView newsView = (ListView) findViewById(R.id.events_list); if (newsView != null) { newsView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Intent intent = new Intent(InterstitialActivity.this, WebViewActivity.class); intent.putExtra("uri", channelArrayList.get(position).getLink()); startActivity(intent); } }); newsView.setAdapter(adapter); } final HandleXML obj = new HandleXML(this); obj.setDataListener(new HandleXML.DataListener() { @Override public void onDataSuccess(final boolean isSuccess) { runOnUiThread(new Runnable() { @Override public void run() { if (isSuccess) { channelArrayList.addAll(obj.getChannelArrayList()); adapter.notifyDataSetChanged(); } else { Log.d(TAG, "Check internet connection"); } } }); } }); obj.fetchXML(Utils.RSS_FEED_URL); } @Override public void onBackPressed() { super.onBackPressed(); Intent intent = new Intent(getApplicationContext(), AdListActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; case R.id.item_setting: displayReplyActivity(); return true; default: Log.e("default item selected", "item"); } return super.onOptionsItemSelected(item); } private void displayReplyActivity() { Intent intentReplyActivity = new Intent(InterstitialActivity.this, SettingActivity.class); startActivity(intentReplyActivity); } private void loadInterstitial() { mInterstitialAd = new LVDOInterstitialAd(this, mApiKey, this); LVDOAdRequest adRequest = new LVDOAdRequest(); 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"); // Loading the ad mInterstitialAd.loadAd(adRequest); } @Override public void onInterstitialLoaded(LVDOInterstitialAd interstitialAd) { Log.d(TAG, "Interstitial Loaded"); mInterstitialAd.show(); } @Override public void onInterstitialFailed(LVDOInterstitialAd interstitialAd, LVDOConstants.LVDOErrorCode errorCode) { Log.v(TAG, "Interstitial Failed" + errorCode.toString()); } @Override public void onInterstitialShown(LVDOInterstitialAd interstitialAd) { Log.d(TAG, "Interstitial Shown"); } @Override public void onInterstitialClicked(LVDOInterstitialAd interstitialAd) { Log.d(TAG, "Interstitial Clicked"); } @Override public void onInterstitialDismissed(LVDOInterstitialAd interstitialAdl) { Log.d(TAG, "Interstitial Dismissed"); } @Override protected void onDestroy() { if (mInterstitialAd != null) { mInterstitialAd.destroyView(); } super.onDestroy(); } @Override protected void onPause() { if (mInterstitialAd != null) { mInterstitialAd.pause(); } super.onPause(); } @Override protected void onResume() { if (mInterstitialAd != null) { mInterstitialAd.resume(); } super.onResume(); } }

See InterstitialActivity.java from Chocolate SSP Demo app for a full example.



Event Listeners

You may optionally track ad lifecycle events like request failures or click-through by implementing LVDOInterstitialListener. This interface may be implemented by your activity or any other object.

public interface LVDOInterstitialListener { // The interstitial has been cached and is ready to be shown. public void onInterstitialLoaded(LVDOInterstitialAd interstitialAd); // The interstitial has failed to load. Inspect errorCode for additional information. public void onInterstitialFailed(LVDOInterstitialAd interstitialAd, LVDOConstants.LVDOErrorCode errorCode) { Log.v(TAG, "Interstitial Failed" + errorCode.toString()); } // The interstitial has been shown. Pause / save state accordingly. public void onInterstitialShown(LVDOInterstitialAd interstitialAd); // The interstitial has been clicked. Take actions accordingly. public void onInterstitialClicked(LVDOInterstitialAd interstitialAd); // The interstitial has been dismissed. Resume / load state accordingly. public void onInterstitialDismissed(LVDOInterstitialAd interstitialAdl); }

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.