开发者

AdMob Ad not showing in emulator, android

Java class code(in onCreate method):

AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest MyAdRequest = new AdRequest();
MyAdRequest.setTesting(true);
adView.loadAd(MyAdRequest);

layout/main.xml code:

<com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        ads:adUnitId="My_AD_PUBLISHER_ID" ads:adSize="BANNER"
        android:layout_alignParentBottom="true" android:layout_centerInParent="true" />

values/attrs.xml code:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="com.google.ads.AdView">
        <attr name="adSize">
            <enum name="BA开发者_如何学编程NNER" value="1" />
            <enum name="IAB_MRECT" value="2" />
            <enum name="IAB_BANNER" value="3" />
            <enum name="IAB_LEADERBOARD" value="4" />
        </attr>
        <attr name="My_AD_PUBLISHER_ID" format="string" />
    </declare-styleable>
</resources>

In Manifest file, before application tag ends:

    <activity android:name="com.google.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation" />

Before manifest Tag ends:

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

Library has also been included from properties to Java build path and in place of My_AD_PUBLISHER_ID, i have carefully placed my actual adcode

After doing all this, ad is showing, NEITHER in emulator NOW on device. pleae guide me what am i missing?


As you mentioned your LogCat says:

onFailedToReceiveAd(A network error...

this means it is a network problem. Even you can load web browse, it doesn't mean the network is okay, it might be blocked by the firewall or other network configurations. I had the same problem before.

If you try on real device instead of simulator, the test ad not showing might be caused by other admob issues other than network problem. The most common admob issue is "No Ad to Show" error which has something to do with Admob fill rate.


If like me you have mobile broadband you need to establish a connection on the internet prior to starting the emulator or it does not seem to get a connection


In your resources file, I noticed you have

<attr name="My_AD_PUBLISHER_ID" format="string" />

Where it should read

<attr name="adUnitId" format="string" />

Not sure if this is a typo from when you copied to StackOverflow, or not. I believe this would cause an build error?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜