Admob ad will not load. Error 2. It worked before but suddenly stopped

后端 未结 12 1808
长情又很酷
长情又很酷 2020-12-11 01:29

Here is the entire class that I am trying to load a banner ad into (createAd() method does the work)

public class HomeActivity extends Activity {

    privat         


        
相关标签:
12条回答
  • 2020-12-11 01:48

    If using real device, check also other apps, you know they contain ads, if ads are shown. Also check individually on mobile network and on Wi-Fi.

    For me, it does not show only on mobile network and in all apps. Deleting data of Google Play Services help me, and ads starts showing again. Until GPS downloads its data back. So it worked for about one minute. :-D

    0 讨论(0)
  • 2020-12-11 01:50

    at first be clear about which type of add you want to load, interstitial or banner ad. if you want to load banner ad, create a banner ad_unit_id on admob site, then use AdView directly inside your activity view as below:

     <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/xadView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/admob_banner_ad_unit_id" />
    

    and just request to load banner ad from your code as below: write this code in your activity inside oncreate after setcontentview

    AdView mAdView = (AdView) findViewById(R.id.xadView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(
                    AdRequest.DEVICE_ID_EMULATOR).build();
    mAdView.loadAd(adRequest); 
    

    AND

    if you want to load interstial ads, create a interstitial ad_unit_id on admob site, then use it in below method:

    public void showFullScreenAd() {
        try {
    
                    com.google.android.gms.ads.InterstitialAd interstitial = new com.google.android.gms.ads.InterstitialAd(context);
                    interstitial
                            .setAdUnitId(ADMOB_INTERSTITIAL_AD_UNIT_ID);
    
                    // Check the logcat output for your hashed device ID to get test ads
                    // on
                    // a physical device.
                    com.google.android.gms.ads.AdRequest adRequest = new AdRequest.Builder()
                            .build();
    
                    // Load the interstitial ad.
                    interstitial.loadAd(adRequest);
                    interstitial
                            .setAdListener(new com.google.android.gms.ads.AdListener() {
                                @Override
                                public void onAdLoaded() {
                                    interstitial.show();
                                }                           
                            });
    
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    

    NOTE: important thing is that sometimes we use banner ad unit id inside interstitial ads or interstitial ad unit id inside banner ads, so this error occurs.

    0 讨论(0)
  • 2020-12-11 01:51

    In our case, our company had some settings in the firewall to block ads. It worked when I switched to an open internet connection without a firewall.

    0 讨论(0)
  • 2020-12-11 01:54

    I had the similar problem. The internet connection was OK and there was no ad blocker installed.

    The problem might be related with your test device. Check if you have another application that contains Admob with your test device. You can also check with another device and another app that contains Admob.

    In my case I realized that my test device has the internet connection but doesn't show up any Admob ads in different applications. So I tried to restart my test device and It worked.

    0 讨论(0)
  • 2020-12-11 01:55

    try 'disable background data on mobile networks' set as disable in google services, it work for me

    0 讨论(0)
  • 2020-12-11 02:00

    In the emulator of Android Studio my issue was the wrong virtual location of the device: once I set it as my real location it started working.

    0 讨论(0)
提交回复
热议问题