user13327428
user13327428

Reputation:

Admob Interstitial ad showing Error building request URL

I have implemented admob interstitial ad recently and getting exception/error as Error building request URL. from method onAdFailedToLoad(), and also my ad is not shown .

My code:

InterstitialAd interstitialAd;
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
        
                InterstitialAd interstitialAd = new InterstitialAd(MainActivity.this);
                interstitialAd.setAdUnitId(KEY);
                MobileAds.initialize(MainActivity.this, new OnInitializationCompleteListener() {
                    @Override
                    public void onInitializationComplete(InitializationStatus initializationStatus) {
                        Log.e("app","MobileAds onInitializationComplete");
                    }
                });
                interstitialAd.loadAd(new AdRequest.Builder().build());
                interstitialAd.setAdListener(new AdListener(){
                    @Override
                    public void onAdLoaded() {
                        Log.e("app","ad loaded");
                    }
        
                    @Override
                    public void onAdFailedToLoad(LoadAdError loadAdError) {
                        Log.e("app","ad failedToLoad: "+loadAdError.getMessage()); //error/exception here
                    }
                });
}
                  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if(interstitialAd.isLoaded()) {
                    interstitialAd.show();
                    Log.e("app","ad loaded");
                }
                else Log.e("app","ad not loaded yet");              
    }
}

I have registered my id properly in the Manifest.xml

<application>
<meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="@string/KEY"/>
    </application>

Followed same guideline shown in here

Upvotes: 5

Views: 8651

Answers (5)

Sambhav Khandelwal
Sambhav Khandelwal

Reputation: 3765

Never use App id from the console to Test ads in your app. Instead use these sample id's:

Ad format Sample Ad Unit Id How it looks
App Open ca-app-pub-3940256099942544/3419835294
Banner ca-app-pub-3940256099942544/6300978111
Interstitial ca-app-pub-3940256099942544/1033173712 No preview
Interstitial Video ca-app-pub-3940256099942544/8691691433

And a lot more. You can find all of them here

Upvotes: 1

Jorgesys
Jorgesys

Reputation: 126455

For instersticial Ad the Sample ad unit ID must be: ca-app-pub-3940256099942544/1033173712

Here is the demo ad units that point to specific test creatives for each format.

enter image description here

Upvotes: 0

Jan Rozenbajgier
Jan Rozenbajgier

Reputation: 634

I've noticed that this error occurs in these cases:

  • When you type wrong adUnitId.
  • When you pass wrong AdSize (ex. too big or too small).
  • When Google stops displaying ads in your app, because you break some admob rules.

Upvotes: 5

Farid Savad
Farid Savad

Reputation: 163

I had a similar problem, after checking I found out that I entered the unit ID incorrectly.

Upvotes: 2

Uwe Post
Uwe Post

Reputation: 515

Make sure you use the correct test ad ID from AdMob in the call InterstitialAd. This is not the same as your App ID, it has an attached slash and a number behind it.

For testing, use ca-app-pub-3940256099942544/1033173712 which is the test ID given by the docs at the time of writing.

Upvotes: 7

Related Questions