Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admob ad never displays in View

Tags:

android

admob

I am trying to get AdMob ads to display in my android application and have been unable to do so. I have contacted their support and have not received any response in almost a week, so I figured I would now ask for help here.

First some code:
AndroidManifest.xml

<manifest 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:versionCode="1" package="com.foo.application">
  <application>
    <meta-data 
        android:value="admob-publisher-id-here" 
        android:name="ADMOB_PUBLISHER_ID" />
  </application>

  <uses-permission android:name="android.permission.INTERNET" />
</manifest>

Yes, admob-publisher-id-here is my real publisher id in the actual manifest file.

main_layout.xml

<LinearLayout 
    android:id="@+id/adhost" 
    android:layout_width="fill_parent"
    android:padding="5dip" android:layout_height="wrap_content"
    android:minHeight="20dip" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res/com.foo.application">
  <com.admob.android.ads.AdView 
      android:id="@+id/ad" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      app:backgroundColor="#000000" 
      app:primaryTextColor="#FFFFFF" 
      app:secondaryTextColor="#CCCCCC"
      app:keywords="android at&amp;t t-mobile iphone blah"/>
</LinearLayout>

attr.xml

<resources>
  <declare-styleable name="com.admob.android.ads.AdView">            
    <attr name="backgroundColor" format="color" />
    <attr name="primaryTextColor" format="color" />
    <attr name="secondaryTextColor" format="color" />
    <attr name="keywords" format="string" />
    <attr name="refreshInterval" format="integer" />
  </declare-styleable>
</resources>

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.admob.android.ads.AdManager;
import com.admob.android.ads.AdView;

import com.foo.application.R;

public class MainActivity extends Activity {
  private AdView ad;

  public MainActivity ( ) {
        AdManager.setTestDevices ( new String[] {
      // made this up for this
            "012345678994814751742145548AAAAAAA" 
        } );
        AdManager.setTestAction ( "url" );
    }

    @Override
    public void onCreate ( Bundle savedInstanceState ) {
      super.onCreate ( savedInstanceState );
        setContentView(R.layout.main_layout);

        if ( AdManager.isTestDevice ( this ) ) {
          // this logs
            Log.w ( "foo-app", "we are on a test device" );
        }

        ad = ( AdView ) this.findViewById ( R.id.ad );
        if ( ad != null ) {
            ad.setVisibility ( View.VISIBLE );
            ad.setAdListener ( new AdListener () );
        }
    }
}

AdListener.java

package com.foo.application

import android.util.Log;

import com.admob.android.ads.AdView;
import com.admob.android.ads.SimpleAdListener;

class AdListener extends SimpleAdListener {
    @Override
    public void onFailedToReceiveAd ( AdView adView ) {
      // this is what logs
        Log.w ( "foo-app", "failed to receive ad" );
        super.onFailedToReceiveAd ( adView );
    }

    @Override
    public void onFailedToReceiveRefreshedAd ( AdView adView ) {
        Log.w ( "foo-app", "failed to receive refreshed ad" );
        super.onFailedToReceiveRefreshedAd ( adView );
    }

    @Override
    public void onReceiveAd ( AdView adView ) {
        Log.w ( "foo-app", "receive ad" );
        super.onReceiveAd ( adView );
    }

    @Override
    public void onReceiveRefreshedAd ( AdView adView ) {
        Log.w ( "foo-app", "receive refreshed ad" );
        super.onReceiveRefreshedAd ( adView );
    }
}

In the logcat, i see the following:

INFO/AdMobSDK(29541): To get test ads on this device use AdManager.setTestDevices( new String[] { "012345678994814751742145548AAAAAAA" } )
WARN/AdMobSDK(29541): Ignoring requestFreshAd() because we are requesting an ad right now already.
WARN/AdMobSDK(29541): Ignoring requestFreshAd() because we are requesting an ad right now already.
WARN/foo-app(29541): we are on a test device
WARN/foo-app(29541): failed to receive ad

The AdListener is indicating that it is unable to retrieve the ad. I have an active data connection, plus I am in Test Mode, so it is supposed to always show an ad, according to the admob wiki. There are no errors in the logcat, nor is the application force closing at all.

Anyone have any ideas or do you see something I am doing wrong?

update: I got a response from admob, but all they said was i was creating the aeveiw twice, which I am not

like image 511
Ryan Conrad Avatar asked Aug 26 '10 15:08

Ryan Conrad


People also ask

Why are my banner ads not showing up?

Ads won't show if you haven't integrated the Google Mobile Ads SDK correctly. Is your ad implementation code working properly? Test your implementation code to check that ads can show. You can also use ad inspector to test your app's ad serving.

How long does it take for AdMob to show ads?

Ad serving When apps are newly registered with AdMob, it typically takes up to an hour and a few ad requests to allow inventory to build. Because of this, you may not see live impressions immediately. Note: In some cases, it may take longer than an hour. Please wait 24 hours before seeking additional help.

How do I know if AdMob ad is working?

Test devices You can configure your device as a test device and use your own ad unit IDs that you've created in your AdMob account. When you enable a test device, the AdMob Network sends production ads in test mode to your device using the ad unit IDs you've created in your AdMob account.

Why did my AdMob app stop showing ads?

Because, if one of your app is removed from the Google Play Store, AdMob Team will stop the ads associated to the application package removed on the Google Play Store. If the same AdMob banner unit id is used in other apps, the ads will be stopped in all your apps. It is a big risk for your business !


1 Answers

Admob should have included this as a warning, but I digress...

In your layout you have android:padding="5dip" this of course causes phones like the G1 to 'lose' some of their available screen real-estate (below 320dip width). Which is of course the minimum width for an admob ad, causing it to fail. Then calling onFailedToReceiveAd in the listener with no explanation whatsoever.

The logs only contain

WARN/AdMobSDK(347): Ignoring requestFreshAd() because we are requesting an ad right now already.

The fix is simple, don't use padding or margins in the root of your layouts that contain ads. Took some experimentation, but it works.

like image 89
smith324 Avatar answered Nov 14 '22 11:11

smith324