Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't get AdMob running on emulator (android 2.2)

I'm just trying to get admob running and tested different "working" code examples from here. None of them works.

In the activity I have:

oncreate()

    AdView ad = (AdView) findViewById(R.id.ad);
    AdRequest r = new AdRequest();
    r.addTestDevice("X3XFX518X7DE1FD879XA5XXAX1AX8BXX"); //no clue why this string
    ad.loadAd(r);

In the view definition I have inserted the following (and yes instead of myPubID there is actually my real PUB ID):

<com.google.ads.AdView 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ads:adUnitId="<myPubID>" 
    ads:adSize="BANNER"/>  

All I get is a black screen for 1 second.

Following log (logcat) is printed during execution

08-09 10:45:03.527: INFO/ActivityManager(59): Start proc de.syrtec.android.bogloid for activity de.syrtec.android.bogloid/.StartSeite: pid=4402 uid=10043 gids={3003}
08-09 10:45:04.887: ERROR/Ads(4402): Could not get currentAdManager.
08-09 10:45:05.397: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@450d4998
08-09 10:45:05.567: INFO/Ads(4402): To get test ads on this device, call adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
08-09 10:45:06.159: INFO/Ads(4402): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":0,"u_sd":1.5,"slotname":"********;</script></head><body></body></html>
08-09 10:45:07.528: WARN/webcore(4402): Can't get the viewWidth after the first layout
08-09 10:45:07.848: INFO/Ads(4402): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=0&u_sd=1.5&slotname=*****: "null">
08-09 10:45:08.809: DEBUG/webviewglue(4402): nativeDestroy view: 0x2bbb30
08-09 10:45:08.818: INFO/Ads(4402): onFailedToReceiveAd(Ad request successful, but no ad returned due to lack of ad inventory.)
08-09 10:45:11.168: DEBUG/dalvikvm(3148): GC_EXPLICIT freed 32 objects / 1640 bytes in 131ms
08-09 10:45:16.237: DEBUG/dalvikvm(272): GC_EXPLICIT freed 195 objects / 12168 bytes in 137ms

I use GoogleAdMobAdsSdk-4.1.1.jar and Android 2.2 on Emulator.

In my admob account there is no filter and adsense is activated.

I also tried it by instanciating the AdView and adding it to the rootlayout with: (referring to http://code.google.com/mobile/ads/docs/android/fundamentals.html)

AdView adView = new AdView(this, AdSize.BANNER, "PUB_ID");
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
layout.addView(adView);
adView.loadAd(new AdRequest());

and got the same behaviour with the following log:

08-09 10:49:18.367: INFO/ActivityManager(59): Start proc de.syrtec.android.bogloid for activity de.syrtec.android.bogloid/.StartSeite: pid=4543 uid=10043 gids={3003}
08-09 10:49:19.297: ERROR/Ads(4543): Could not get currentAdManager.
08-09 10:49:19.797: WARN/ActivityManager(59): Activity pause timeout for HistoryRecord{44fe4350 de.syrtec.android.bogloid/.StartSeite}
08-09 10:49:20.067: INFO/Ads(4543): To get test ads on this device, call adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
08-09 10:49:20.379: INFO/Ads(4543): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script*****;</script></head><body></body></html>
08-09 10:49:20.397: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@450d20b8
08-09 10:49:22.737: WARN/webcore(4543): Can't get the viewWidth after the first layout
08-09 10:49:22.957: INFO/Ads(4543): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=0&u_sd=1.5&slotname=***** "null">
08-09 10:49:24.038: DEBUG/dalvikvm(4543): GC_FOR_MALLOC freed 3826 objects / 234984 bytes in 154ms
08-09 10:49:24.058: DEBUG/webviewglue(4543): nativeDestroy view: 0x2c5320
08-09 10:49:24.058: INFO/Ads(4543): onFailedToReceiveAd(Ad request successful, but no ad returned due to lack of ad inventory.)
08-09 10:49:24.078: DEBUG/webviewglue(4543): nativeDestroy view: 0x2b81d0

Has anyone a clue?

like image 268
syr Avatar asked Aug 09 '11 10:08

syr


2 Answers

I tried like in the suggested tutorial (blog.kerul.net/2011/05/)

but I only get a black view for a second and then return to android "desktop":

The source looks now like this:

activity class:

class StartActivity extends AdActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    AdView adview = (AdView)findViewById(R.id.adView1);
    AdRequest re = new AdRequest();
    re.addTestDevice(AdRequest.TEST_EMULATOR);
    re.setTesting(true);
    adview.loadAd(re);
}
...
}

the view:

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

    <com.google.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/adView1" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        ads:adSize="BANNER"
        ads:adUnitId="MY_PUB_ID" />

</LinearLayout>

And YES I replaced MY_PUB_ID with my real publisher id

Is there anything missing? What Emulator do you use with which Android runtime?

like image 161
syr Avatar answered Nov 01 '22 10:11

syr


You need to place to the //no clue why this string your test device's code. I prefer to use setTesting(true) while test it, but you know. The problem can be this.

Oh and I see that your program can't receive ad because of the fault of the ad inventory Place this in your layout at the com.google.ads.adView section: xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

And not forget to take an Internet permission to your manifest.

Hope it helps.

Edit: I'm not sure that this is your problem, but I think it can helps.

like image 31
Zwiebel Avatar answered Nov 01 '22 10:11

Zwiebel