AdMob Banner not working on mobile data

2019-03-22 00:13发布

问题:

I've recently started in Android App developing and I'm a getting the following error in logcat when trying to load the banner in my app.

03-02 17:30:58.509: I/Ads(12181): Use AdRequest.Builder.addTestDevice("My device ID") to get test ads on this device.
03-02 17:30:58.509: I/Ads(12181): Starting ad request.
03-02 17:30:58.799: W/Ads(5515): Error while connecting to ad server: failed to connect to googleads.g.doubleclick.net/74.125.225.250 (port 80) after 60000ms: isConnected failed: ENETUNREACH (Network is unreachable)
03-02 17:30:58.799: W/Ads(12181): There was a problem getting an ad response. ErrorCode: 2
03-02 17:30:58.939: I/Ads(12181): Scheduling ad refresh 60000 milliseconds from now.
03-02 17:30:58.939: W/Ads(12181): Failed to load ad: 2

It only happens in certain devices (Mostly in Android 4.1 Jelly Bean) and only on mobile data (Using Telcel México), it works as expected on WiFi.

My xml and java code is the same as the AdMob implementation guide.

layout.xml banner

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="My Add Unit Id (Hidden)" />

MainActivity onCreate Method

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AdView adView = (AdView) this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
    }

Hope you can help me solve this.

回答1:

Error 2 appears if date or time is wrong Just set autodate correcting on your device. Error 2 appears if time on your device is not equals with time on google service. It's all what you need



回答2:

Probably the DNS provider used has some problem to reach the AdMob server (or are applied some filters to reduce the traffic on ad servers).



回答3:

Not really an answer, but noticed you didn't copy out your layout.xml header, there's an xml directive that needs to be in there. But yes, the probelm is the ad library can't reach the admob server.



回答4:

I had the same problem, and ... yeah... I turned off the WiFi on my phone, and then it worked perfectly. So in my case, i think it was lag/interference from my router.