开发者

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

开发者 https://www.devze.com 2023-03-27 05:57 出处:网络
I\'m just trying to get admob running and tested different \"working\" code examples from here. None of them works.

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: ER开发者_如何学JAVAROR/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?


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?


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.


Lack of inventory means AdMob doesn't have any ads to serve, this is usual if your account is new, after a while your fill-rate will increase and more ads will be served. If you see a green status light in your AdMob sites/app page, you shouldn't worry Try adding adsense to increase your fill-rate Enabling Google AdSense Ads in Your Applications.

edit: missed you already had adsense enabled


I have this experience of having the apps crashing and displaying messages such as this - "Error inflating class com.admob.ads.AdView" . Doing some research and testing I concluded the following XML attribute to display the AdView;

`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/bg1"
android:orientation="vertical" >

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <com.google.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="738a44d913034b9f"
        />  
</TableRow>

<TableRow
    android:id="@+id/tableRow3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/txtsearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:inputType="textMultiLine"
        android:maxLines="3"
        android:minLines="1"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical" />

</TableRow>

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >







    <Button
        android:id="@+id/btnkamus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableRight="@drawable/search" />




    <Button
        android:id="@+id/btnsearch"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="Kesan" />


    <Button
        android:id="@+id/btncadang"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="Cadang" />

</TableRow>


<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>`

Complete tutorial is here - http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号