I am using Millennial Media SDK and writing a Cordova/PhoneGap plugin for mMedia Ad, it works pretty well on iOS and video Ad, but I have some trouble when using banner AD on Android.
If I insert the MMAdView as brother view of Cordova WebView (docking at top or bottom), the banner Ad always display a full screen white space, which covers the WebView.
When I write log to check the size of MMAdView with getWidth()
or getMeasuredWidth()
, it always return 0 or 1 instead of the actual size!
It's quite similar to this question, the difference is I am using pure java code instead of XML layout file.
AdMob mediated Millenial Media ad taking entire screen on refresh
See the screenshot:
Here is the code:
adView = new MMAdView(cordova.getActivity());
adView.setApid( bannerAdId );
adView.setId(MMSDK.getDefaultAdId());
width = BANNER_AD_WIDTH;
height = BANNER_AD_HEIGHT;
//Finds an ad that best fits a users device.
if(canFit(MED_BANNER_WIDTH)) {
width = MED_BANNER_WIDTH;
height = MED_BANNER_HEIGHT;
} else if(canFit(IAB_LEADERBOARD_WIDTH)) {
width = IAB_LEADERBOARD_WIDTH;
height = IAB_LEADERBOARD_HEIGHT;
}
adView.setWidth(width);
adView.setHeight(height);
adView.setListener(new BannerListener());
adView.getAd();
ViewGroup parentView = (ViewGroup) webView.getParent();
if(argPos <= TOP_RIGHT) {
parentView.addView(adView, 0);
} else {
parentView.addView(adView);
}