简体   繁体   中英

AdMob Banner and Interstitial Ad Failure to Load

I am working on an Android app that uses AdMob. I am loading a banner and and an interstitial ad. I can not get the add to load. I keep getting the same error pattern in the logcat, but can not figure out how to update in order to resolve the error. I will enclose my xml and java files along with my logcat. I have searched a previous post and saw something kind of similar but it was unresolved.

Java:

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {
    private InterstitialAd mInterstitialAd;

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

        MobileAds.initialize(getApplicationContext(), "ca-app-pub-8163174299019987/4501487157");
        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);


        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-8163174299019987/4442611559");
        AdRequest intadRequest = new AdRequest.Builder()
                .addTestDevice("YOUR_DEVICE_HASH")
                .build();

        mInterstitialAd.loadAd(intadRequest);
        Button btn1 = (Button) findViewById(R.id.btn1);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
                startActivity(new Intent(MainActivity.this, Game.class));
            }
        });

    }
}

XML

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-8163174299019987/4501487157"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>

Logcat
06-17 10:59:42.750 20745-20745/com.marijuanastrainquiz I/Ads: Starting ad request.
06-17 10:59:42.801 20745-20745/com.marijuanastrainquiz W/GooglePlayServicesUtil: Google Play services out of date.  Requires 9080000 but found 8489470
06-17 10:59:42.957 20745-20745/com.marijuanastrainquiz W/art: Verification of void com.google.android.gms.ads.internal.zzl.zzbO() took 103.363ms
06-17 10:59:43.008 20745-20755/com.marijuanastrainquiz I/art: Background sticky concurrent mark sweep GC freed 10140(1841KB) AllocSpace objects, 64(1912KB) LOS objects, 16% free, 8MB/10MB, paused 544us total 207.601ms
06-17 10:59:43.008 20745-20745/com.marijuanastrainquiz I/Ads: Starting ad request.
06-17 10:59:43.090 20745-20853/com.marijuanastrainquiz W/GooglePlayServicesUtil: Google Play services out of date.  Requires 9080000 but found 8489470
06-17 10:59:43.090 20745-20853/com.marijuanastrainquiz W/Ads: Failed to connect to remote ad request service.
06-17 10:59:43.090 20745-20853/com.marijuanastrainquiz W/Ads: Could not start the ad request service.
06-17 10:59:43.094 20745-20809/com.marijuanastrainquiz W/GooglePlayServicesUtil: Google Play services out of date.  Requires 9080000 but found 8489470
06-17 10:59:43.094 20745-20809/com.marijuanastrainquiz W/Ads: Failed to connect to remote ad request service.
06-17 10:59:43.094 20745-20809/com.marijuanastrainquiz W/Ads: Could not start the ad request service.
06-17 10:59:43.122 20745-20745/com.marijuanastrainquiz W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
06-17 10:59:43.123 20745-20745/com.marijuanastrainquiz W/Ads: Failed to load ad: 0
06-17 10:59:43.123 20745-20745/com.marijuanastrainquiz W/Ads: Failed to load ad: 0

First you need to check the google play service version of your phone.

You are not putting your device hash.

AdRequest intadRequest = new AdRequest.Builder()
            .addTestDevice("YOUR_DEVICE_HASH")
            .build();

Here you need to replace YOUR_DEVICE_HASH with your device id to start getting test ads.

Hope it will help :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM