Also ensure that the banner view/container in which the banner will appear is not visible by default. Use the onAdStarted() callback to make the banner view/container visible and hide it using onAdDismissed() so as to avoid any conflict with Ad network banners from mediation partners.
For your reference purpose, We have created VMAX Sample App for Banner adspot. This app is open source and uploaded on Github where you can download and read example code for requesting Banner Ads
Click here to download Banner demo App
SDK 3.6.0 onwards
Create below VmaxAdview in your main Layout file
1 2 3 4 5 6 7 8 9 10 |
<com.vmax.android.ads.api.VmaxAdView android:id="@+id/banner_adview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:visibility="gone" app:vmax_UX_type="0" app:vmax_adspot_id="" /> |
Code to invoke Banner Ads in your Activity class
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 |
VmaxAdView vmaxAdView = (VmaxAdView) findViewById(R.id.banner_adview); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public void onAdError(VmaxAdError error) { } @Override public void onAdReady(VmaxAdView adView) { adView.setVisibility(View.VISIBLE); } @Override public void onAdDismissed(VmaxAdView adView) { adView.setVisibility(View.GONE); } @Override public void onAdStarted(VmaxAdView adView) { adView.setVisibility(View.VISIBLE); } @Override public void onAdEnd(boolean isVideoCompleted, long reward) { } }); vmaxAdView.loadAd(); |
Create below Layout in main layout file
1 2 3 4 5 6 7 8 |
<FrameLayout android:id="@+id/banner_adview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:visibility="gone" /> |
Code to invoke Banner Ads in your Activity class
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 |
VmaxAdView vmaxAdView = new VmaxAdView(this,"",VmaxAdView.UX_BANNER); final FrameLayout bannerAdLayout = (FrameLayout) findViewById(R.id.banner_adview); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public void onAdError(VmaxAdError error) { } @Override public void onAdReady(VmaxAdView adView) { bannerAdLayout.removeAllViews(); bannerAdLayout.addView(adView); bannerAdLayout.setVisibility(View.VISIBLE); } @Override public void onAdDismissed(VmaxAdView adView) { bannerAdLayout.setVisibility(View.GONE); } @Override public void onAdStarted(VmaxAdView adView) { bannerAdLayout.setVisibility(View.VISIBLE); } @Override public void onAdEnd(boolean isVideoCompleted, long reward) { } }); vmaxAdView.loadAd(); |
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 37 38 39 40 |
@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 a banner ad in one Activity and show it in a different Activity.
To Cache Banners Programmatically
Code to invoke Banner Ads in your Activity class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
VmaxAdView vmaxAdView = VmaxAdView.getMutableInstance(this,"your adspot id",VmaxAdView.UX_BANNER); 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.setRefresh(false); vmaxAdView.cacheAd(); |
To Show Banners Programmatically
Create below Layout in main layout file
1 2 3 4 5 6 |
<FrameLayout android:id="@+id/banner_adview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:visibility="gone" /> |
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 |
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) { } }); FrameLayout banner_adview=(FrameLayout) findViewById(R.id.banner_adview); if (vmaxAdView.getContext() != null) { ((MutableContextWrapper) vmaxAdView.getContext()).setBaseContext(this); } banner_adview.removeAllViews(); banner_adview.addView(vmaxAdView); banner_adview.setVisibility(View.VISIBLE); //AdStates are available on SDK version 3.6.1 onwards if (vmaxAdView.getAdState() == VmaxAdView.AdState.STATE_AD_READY) vmaxAdView.showAd(); |
Before SDK 3.6.0
Create below VmaxAdview in your main Layout file
1 2 3 4 5 6 7 8 9 10 |
<com.vmax.android.ads.api.VmaxAdView android:id="@+id/banner_adview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:visibility="gone" app:vmax_UX_type="0" app:vmax_adspot_id="" /> |
Code to invoke Banner Ads in your Activity class
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
VmaxAdView vmaxAdView = (VmaxAdView) findViewById(R.id.banner_adview); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public VmaxAdView didFailedToLoadAd(String s) { return null; } @Override public VmaxAdView didFailedToCacheAd(String s) { return null; } @Override public void adViewDidLoadAd(VmaxAdView adView) { adView.setVisibility(View.VISIBLE); } @Override public void adViewDidCacheAd(VmaxAdView adView) { } @Override public void didInteractWithAd(VmaxAdView adView) { } @Override public void willDismissAd(VmaxAdView adView) { adView.setVisibility(View.GONE); } @Override public void willPresentAd(VmaxAdView adView) { adView.setVisibility(View.VISIBLE); } @Override public void willLeaveApp(VmaxAdView adView) { } @Override public void onVideoView(boolean b, int i, int i1) { } @Override public void onAdExpand() { } @Override public void onAdCollapsed() { } }); vmaxAdView.loadAd(); |
Create below Layout in main layout file
1 2 3 4 5 6 7 8 |
<FrameLayout android:id="@+id/banner_adview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:visibility="gone" /> |
Code to invoke Banner Ads in your Activity class
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
VmaxAdView vmaxAdView = new VmaxAdView(this,"",VmaxAdView.UX_BANNER); final FrameLayout bannerAdLayout = (FrameLayout) findViewById(R.id.banner_adview); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public VmaxAdView didFailedToLoadAd(String s) { return null; } @Override public VmaxAdView didFailedToCacheAd(String s) { return null; } @Override public void adViewDidLoadAd(VmaxAdView adView) { bannerAdLayout.removeAllViews(); bannerAdLayout.addView(adView); bannerAdLayout.setVisibility(View.VISIBLE); } @Override public void adViewDidCacheAd(VmaxAdView adView) { } @Override public void didInteractWithAd(VmaxAdView adView) { } @Override public void willDismissAd(VmaxAdView adView) { bannerAdLayout.setVisibility(View.GONE); } @Override public void willPresentAd(VmaxAdView adView) { bannerAdLayout.setVisibility(View.VISIBLE); } @Override public void willLeaveApp(VmaxAdView adView) { } @Override public void onVideoView(boolean b, int i, int i1) { } @Override public void onAdExpand() { } @Override public void onAdCollapsed() { } }); vmaxAdView.loadAd(); |
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 37 38 39 40 |
@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 a banner ad in one Activity and show it in a different Activity.
To Cache Banners Programmatically
Code to invoke Banner Ads in your Activity class
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 37 38 39 40 |
VmaxAdView vmaxAdView = VmaxAdView.getMutableInstance(this,"your adspot id",VmaxAdView.UX_BANNER); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public VmaxAdView didFailedToLoadAd(String s) { return null; } @Override public VmaxAdView didFailedToCacheAd(String s) { return null; } @Override public void adViewDidLoadAd(VmaxAdView adView) { } @Override public void adViewDidCacheAd(VmaxAdView adView) { } @Override public void didInteractWithAd(VmaxAdView adView) { } @Override public void willDismissAd(VmaxAdView adView) } @Override public void willPresentAd(VmaxAdView adView) { } @Override public void willLeaveApp(VmaxAdView adView) { } @Override public void onVideoView(boolean b, int i, int i1) { } @Override public void onAdExpand() { } @Override public void onAdCollapsed() { } }); vmaxAdView.setRefresh(false); vmaxAdView.cacheAd(); |
To Show Banners Programmatically
Create below Layout in main layout file
1 2 3 4 5 6 |
<FrameLayout android:id="@+id/banner_adview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:visibility="gone" /> |
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 37 38 39 40 41 42 43 44 45 46 |
AdContainer singleton = AdContainer.getInstance(); VmaxAdView vmaxAdView= singleton.getAdView("your adspot id"); vmaxAdView.setAdListener(new VmaxAdListener() { @Override public VmaxAdView didFailedToLoadAd(String s) { return null; } @Override public VmaxAdView didFailedToCacheAd(String s) { return null; } @Override public void adViewDidLoadAd(VmaxAdView adView) { } @Override public void adViewDidCacheAd(VmaxAdView adView) { } @Override public void didInteractWithAd(VmaxAdView adView) { } @Override public void willDismissAd(VmaxAdView adView) } @Override public void willPresentAd(VmaxAdView adView) { } @Override public void willLeaveApp(VmaxAdView adView) { } @Override public void onVideoView(boolean b, int i, int i1) { } @Override public void onAdExpand() { } @Override public void onAdCollapsed() { } }); FrameLayout banner_adview=(FrameLayout) findViewById(R.id.banner_adview); if (vmaxAdView.getContext() != null) { ((MutableContextWrapper) vmaxAdView.getContext()).setBaseContext(this); } banner_adview.removeAllViews(); banner_adview.addView(vmaxAdView); banner_adview.setVisibility(View.VISIBLE); vmaxAdView.showAd(); |