0

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? PhoneGap view missing

4

1 回答 1

3

解决了!方法如下,希望对某人有所帮助:

public void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  super.loadUrl(Config.getStartUrl());
  LinearLayout layout = super.root;
  moPubView = new MoPubView(this);
  moPubView.setAdUnitId(MO_PUBID);
  moPubView.loadAd();
  layout.addView(moPubView);
}
于 2013-08-11T22:40:23.737 回答