Question

I am implementing InterstitialAd in my app, and follows the Google code example to implement the ad.

Question:

The Ad most of the time cannot be shown properly. I have already set all the activities and also the AdActivity in the Manifest forcing them to be orientation being protrait. Yet it still fails. Are there anyone that know what is the problem? Million thanks!

PS: I am not promoting any ad here..just to have a screencapture here for the problem I met

Ad when it is ok:

enter image description here

But most of the time it is out of screen: it becomes horizontal and have white blank screen at the bottom

enter image description here

Code:

    interstitialAd = new InterstitialAd(this, MY_PUBLISHER_ID); 
    interstitialAd.setAdListener(this); // Set the AdListener.
    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
    interstitialAd.loadAd(adRequest);

Manifest:

<application
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Abc"
        android:screenOrientation="portrait"
        android:label="@string/title_activity_startup" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity
    android:name="com.google.ads.AdActivity"
    android:screenOrientation="portrait"           
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
Was it helpful?

Solution 2

I have reproduced this issue with 100% reproducibility. Look for workaround below.

Description:
Admob interstitial is shown incorrectly on Android

Steps to reproduce:

  1. Download admob interstitial sample using link "Download the example project" on page: https://developers.google.com/mobile-ads-sdk/docs/admob/advanced
  2. Open InterstitialSample.java
  3. Find in onCreate method the following 2 lines of code:

    interstitialAd = new InterstitialAd(this, AD_UNIT_ID_GOES_HERE);
    interstitialAd.setAdListener(this);

  4. Remove these 2 lines from onCreate method and add them to onClick before interstitialAd.loadAd(adRequest);
  5. Replace AD_UNIT_ID_GOES_HERE by your id
  6. Add GoogleAdMobAdsSdk-6.3.0.jar to project
  7. Build and run
  8. Click "Load Interstitial" button then "Show Interstitial" button
Observed result:
When device is in portrait orientation an interstitial shows landscape version of ad content, and vice versa when device is in landscape orientation an interstitial shows portrait version of ad content.

Configuration used for testing:
Android OS: 4.2.1 or 4.2.2
GoogleAdMobAdsSdk: 6.2.1 or 6.3.0
Device: Galaxy Nexus

Workaround:
As you can see original sample without modification (when creation of InterstitialAd is done in Activity.onCreate) works properly. So main idea for workaround is to create the same conditions for showing interstitial inside your real application. If you couldn't place code for creating InterstitialAd object inside onCreate method of your real Activity or you need to show interstitial from arbitrary code (for example form inside library code) then you need to create additional "launcher" Activity.

In my case I have used the following steps:
1. Create additional Activity (based on InterstitialSample from Google sample) which will be used as launcher for interstitial ad
2. Add code for creating InterstitialAd object and setting listener inside onCreate method of that Activity
3. Add code for loading interstitial ad to onCreate method
4. Add code for displaying interstitial ad to onReceiveAd listener method
5. Add code for finishing Activity to onFailedToReceiveAd and onDismissScreen listener methods

Then just launch this additional "launcher" Activity whenever you need to show ad. This workaround works for me.

OTHER TIPS

This is fixed now. So no longer the need for the workaround: https://groups.google.com/forum/?fromgroups=#!topic/google-admob-ads-sdk/83DP6aCnwx4

Have the same issue and With some test, I found other stuff would cause this problem. If the app use WebView and developer have the WebView timer paused and then show interstitial ads. It also will cause this problem.

The reason may be interstitial ads depending on HTML/JS. Paused timer will cause abnormal behavior.

The solution could keep the WebView timer, never pause it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top