Madmenyo
Madmenyo

Reputation: 8584

Interstitial ad not being loaded?

I just created a Interstitial add in my test app. Went fairly easy, but now I want to add one to my main application and I cannot seem to load it.

This is what my android launcher looks like:

../

    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        initialize(new GameOfClaws(this), config);

        //initialize ads...
        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId(getString(R.string.interstitial_ad));
        //Load add
        requestNewInterstitial();

        interstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                super.onAdClosed();
                requestNewInterstitial();
            }
            @Override
            public void onAdLoaded()
            {
                Gdx.app.log(TAG, "Ad loaded!");
                //interstitialAd.show();
            }
        });
    }

    private void requestNewInterstitial()
    {
        AdRequest adRequest = new AdRequest.Builder()
                .build();
        interstitialAd.loadAd(adRequest);
    }

    @Override
    public void displayInterstitialAd() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (interstitialAd.isLoaded()) {
                    interstitialAd.show();
                }
                else
                {
                    Gdx.app.log("MainActivity", "Add not loaded!");
                }

            }
        });
    }

/..

I simply call a interface method in the show method of my menuScreen to run the same method in the AndroidLauncher.

resolver.displayInterstitialAd();

It's basically the same as my working test app but there I load the interstitial by pressing a button.

This is my manifest:

<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/GdxTheme" >

    <meta-data android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />

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

    <activity
        android:name="com.madmenyo.gameofclaws.android.AndroidLauncher"
        android:label="@string/app_name" 
        android:screenOrientation="landscape"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

The only things that are different is that my test app is in portrait mode and it has been uploaded a while ago but remains as a testing app and not published. My current app has just been uploaded for testing these ads and the play store. The play store works fine. I also changed the ad ID to the correct ID I got on the Admob website.

Upvotes: 0

Views: 161

Answers (1)

Rama
Rama

Reputation: 1156

Add the following in manifest file

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

Upvotes: 1

Related Questions