Admob is not showing in my SDL game

I wrote an SDL game and ported it to andorid

and now i tried to integrate it with admob but i couldn't

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<!-- Replace org.libsdl.app with the identifier of your game below, e.g.
 com.gamemaker.game
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.libsdl.zomibeshooter"
  android:versionCode="1"
  android:versionName="1.0"
  android:installLocation="auto">

 <!-- Create a Java class extending SDLActivity and place it in a
     directory under src matching the package, e.g.
        src/com/gamemaker/game/MyGame.java

     then replace "SDLActivity" with the name of your class (e.g. "MyGame")
     in the XML below.

     An example Java class can be found in README-android.txt 
 -->
 <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

 <application android:label="@string/app_name"
             android:icon="@drawable/ic_launcher"
             android:allowBackup="true"
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
             android:hardwareAccelerated="true" >
    <activity android:name="mygame"
              android:label="@string/app_name"
              android:configChanges="keyboardHidden|orientation"
              android:screenOrientation="landscape"
              >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


  <meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />


  <activity
      android:name="com.google.android.gms.ads.AdActivity"
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
       android:theme="@android:style/Theme.Translucent" />

</application>



<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" /> 

<!-- Allow writing to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />




</manifest> 

      

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

  <com.google.android.gms.ads.AdView
  android:id="@+id/adView"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  ads:adSize="BANNER"
  ads:adUnitId="xxxxx" />

   </LinearLayout>

      

my SDLActivity.java

// Setup
@Override
protected void onCreate(Bundle savedInstanceState) {


    Log.v("SDL", "onCreate():" + mSingleton);
    super.onCreate(savedInstanceState);


    setContentView(R.layout.main);

 // Prepare the Interstitial Ad
 interstitial = new InterstitialAd(SDLActivity.this);
 // Insert the Ad Unit ID
 interstitial.setAdUnitId("xxxxxxx");

 //Locate the Banner Ad in activity_main.xml
 AdView adView = (AdView) this.findViewById(R.id.adView);

 // Request for Ads
 AdRequest adRequest = new AdRequest.Builder()

 // Add a test device to show Test Ads
 .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
 .addTestDevice("CC5F2C72DF2B356BBF0DA198")
 .build();

 // Load ads into Banner Ads
 adView.loadAd(adRequest);

 // Load ads into Interstitial Ads
 interstitial.loadAd(adRequest);

 // Prepare an Interstitial Ad Listener
 interstitial.setAdListener(new AdListener() {
 public void onAdLoaded() {
 // Call displayInterstitial() function
 displayInterstitial();
 }
 });


    SDLActivity.initialize();
    // So we can call stuff from static callbacks
    mSingleton = this;

    // Set up the surface
    mSurface = new SDLSurface(getApplication());

    if(Build.VERSION.SDK_INT >= 12) {
        mJoystickHandler = new SDLJoystickHandler_API12();
    }
    else {
        mJoystickHandler = new SDLJoystickHandler();
    }

    mLayout = new AbsoluteLayout(this);
    mLayout.addView(mSurface);

    setContentView(mLayout); #########// if i comment this i can see the ad but the game is not show!
}

public void displayInterstitial() {
    // If Ads are loaded, show Interstitial else show nothing.
    if (interstitial.isLoaded()) {
    Log.v("ad","displayed");
    interstitial.show();
    }
    }

      

If I comment this line, I can see the ad, but not the game!

setContentView (mLayout);

So how can I show an ad from the start of my game to its release?

+3


source to share





All Articles