For your reference purpose, We have created VMAX Sample App for Rewarded Video adspot. This app is open source and uploaded on Github where you can download and read example code for requesting Rewarded Video Ads
Click here to download Rewarded Video demo App
Note: For Rewarded inetrstitial it is mandatory to add Firebase dependency in your app’s build.gradle
1 2 3 4 5 |
compile 'com.google.firebase:firebase-database:9.6.0' compile 'com.google.firebase:firebase-auth:9.6.0' compile 'com.google.android.gms:play-services-ads:9.6.0' compile 'com.google.android.gms:play-services-tasks:9.6.0' |
To cache rewarded interstitial ad
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
//Declare vmaxAdReward object globally in order to avoid memory leak private VmaxAdReward vmaxAdReward = new VmaxAdReward() { @Override public void onAdReward(long reward) { } }; /*It is required to initialize VmaxSdk with AccountKey for RewardedInterstitial. Make sure to call it before making ad request and call it only once*/ VmaxSdk.initWithRewardedInterstitial(getApplicationContext(), "AccountKey"); VmaxSdk.registerVmaxAdRewardListener(vmaxAdReward); VmaxAdView vmaxAdView = new VmaxAdView(this,"your adspot id",VmaxAdView.UX_INTERSTITIAL); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public void onAdError(VmaxAdError error) { } @Override public void onAdReady(VmaxAdView adView) { } @Override public void onAdDismissed(VmaxAdView adView) { } @Override public void onAdEnd(boolean isVideoCompleted, long reward) { } }); vmaxAdView.cacheAd(); |
Make sure to unregister VmaxAdReward delegate inside onDestroy() of activity to avoid memory leak
1 2 |
VmaxSdk.unregisterVmaxAdRewardListener(vmaxAdReward); |
To show rewarded interstitial ad
1 2 3 |
//AdStates are available on SDK version 3.6.1 onwards if (vmaxAdView.getAdState() == VmaxAdView.AdState.STATE_AD_READY) vmaxAdView.showAd(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
//Make sure to handle Activity Life cycle callbacks with VmaxAdView @Override protected void onPause() { if (vmaxAdView != null) { vmaxAdView.onPause(); } super.onPause(); } @Override protected void onResume() { if (vmaxAdView != null) { vmaxAdView.onResume(); } super.onResume(); } @Override protected void onDestroy() { if (vmaxAdView != null) { vmaxAdView.onDestroy(); } super.onDestroy(); } @Override public void finish() { if (vmaxAdView != null) { vmaxAdView.finish(); } super.finish(); } @Override public void onBackPressed() { if (vmaxAdView != null) { vmaxAdView.onBackPressed(); } super.onBackPressed(); } |
Advanced
VMAX allows you to cache an interstitial ad in one Activity and show it in a different Activity.
To Cache Rewarded Interstitials
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
private VmaxAdReward vmaxAdReward=new VmaxAdReward() { @Override public void onAdReward(long reward) { } }; //Initialize VmaxSdk with AccountKey for RewardedInterstitial VmaxSdk.initWithRewardedInterstitial(getApplicationContext(), "AccountKey"); VmaxSdk.addVmaxAdRewardListener(vmaxAdReward); VmaxAdView vmaxAdView = VmaxAdView.getMutableInstance(this,"your adspot id",VmaxAdView.UX_INTERSTITIAL); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public void onAdError(VmaxAdError error) { } @Override public void onAdReady(VmaxAdView adView) { } @Override public void onAdDismissed(VmaxAdView adView) { } @Override public void onAdEnd(boolean isVideoCompleted, long reward) { } }); vmaxAdView.cacheAd(); |
To Show Rewarded Interstitials
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
AdContainer singleton = AdContainer.getInstance(); VmaxAdView vmaxAdView= singleton.getAdView("your adspot id"); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public void onAdError(VmaxAdError error) { } @Override public void onAdReady(VmaxAdView adView) { } @Override public void onAdDismissed(VmaxAdView adView) { } @Override public void onAdEnd(boolean isVideoCompleted, long reward) { } }); if (vmaxAdView.getContext() != null) { ((MutableContextWrapper) vmaxAdView.getContext()).setBaseContext(this); } //AdStates are available on SDK version 3.6.1 onwards if (vmaxAdView.getAdState() == VmaxAdView.AdState.STATE_AD_READY) vmaxAdView.showAd(); |
To cache rewarded video ad
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
VmaxAdView vmaxAdView = new VmaxAdView(this,"your adspot id",VmaxAdView.UX_INTERSTITIAL); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public void onAdError(VmaxAdError error) { } @Override public void onAdReady(VmaxAdView adView) { } @Override public void onAdDismissed(VmaxAdView adView) { } @Override public void onAdEnd(boolean isVideoCompleted, long reward) { } }); vmaxAdView.cacheAd(); |
To show rewarded video ad
1 2 3 |
//AdStates are available on SDK version 3.6.1 onwards if (vmaxAdView.getAdState() == VmaxAdView.AdState.STATE_AD_READY) vmaxAdView.showAd(); |
Passing Custom Data
The VMAX SDK allows you to pass extra data that is then available in a postback URL.
1 2 3 4 |
HashMap<String,String> customData=new HashMap<>(); customData.put("key1","value1"); customData.put("key2","value2"); vmaxAdView.setCustomData(customData); |
Visit the VMAX Control Panel and enter the postback URL in Settings >> Apps and Adspots >> Rewarded Video Adspots. Once you define the key value pairs here, and configure the postback URL, you will get these keys and values as additional URL parameters on your server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
//Make sure to handle Activity Life cycle callbacks with VmaxAdView @Override protected void onPause() { if (vmaxAdView != null) { vmaxAdView.onPause(); } super.onPause(); } @Override protected void onResume() { if (vmaxAdView != null) { vmaxAdView.onResume(); } super.onResume(); } @Override protected void onDestroy() { if (vmaxAdView != null) { vmaxAdView.onDestroy(); } super.onDestroy(); } @Override public void finish() { if (vmaxAdView != null) { vmaxAdView.finish(); } super.finish(); } @Override public void onBackPressed() { if (vmaxAdView != null) { vmaxAdView.onBackPressed(); } super.onBackPressed(); } |
Advanced
VMAX allows you to cache an interstitial ad in one Activity and show it in a different Activity.
To Cache rewarded video ad
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
VmaxAdView vmaxAdView = VmaxAdView.getMutableInstance(this,"your adspot id",VmaxAdView.UX_INTERSTITIAL); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public void onAdError(VmaxAdError error) { } @Override public void onAdReady(VmaxAdView adView) { } @Override public void onAdDismissed(VmaxAdView adView) { } @Override public void onAdEnd(boolean isVideoCompleted, long reward) { } }); vmaxAdView.cacheAd(); |
To Show rewarded video
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
AdContainer singleton = AdContainer.getInstance(); VmaxAdView vmaxAdView= singleton.getAdView("your adspot id"); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public void onAdError(VmaxAdError error) { } @Override public void onAdReady(VmaxAdView adView) { } @Override public void onAdDismissed(VmaxAdView adView) { } @Override public void onAdEnd(boolean isVideoCompleted, long reward) { } }); if (vmaxAdView.getContext() != null) { ((MutableContextWrapper) vmaxAdView.getContext()).setBaseContext(this); } //AdStates are available on SDK version 3.6.1 onwards if (vmaxAdView.getAdState() == VmaxAdView.AdState.STATE_AD_READY) vmaxAdView.showAd(); |