I've successfully integrated AdMob ads into my Android PhoneGap apps in the past following this pattern (in main activity), using the LinearLayout widget:
AdMob/PhoneGap Integration - Works - doesn't additional require markup in main.xml
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
adView = new AdView(this, AdSize.BANNER, AdMob_Ad_Unit);
LinearLayout layout = super.root;
layout.addView(adView);
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
}
However, I'd like to follow a similar pattern using MoPub SDK, I tried the following pattern, however, this does not show the PhoneGap "webview" of the app, although it loads the ads correct:
MoPub/PhoneGap Integration - Ads Work, PhoneGap doesn't - requires addition to main.xml
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl(Config.getStartUrl());
setContentView(R.layout.main);
moPubView = (MoPubView) findViewById(R.id.adview);
moPubView.setAdUnitId(MOPUB_ID);
moPubView.loadAd();
}
And in the main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.mopub.mobileads.MoPubView
android:id="@+id/adview"
android:layout_width="fill_parent"
android:layout_height="50dp"
/>
This is what shows up - How can I get PhoneGap to work with MoPub?