Reputation: 99
I am trying to have two banner ads on the same page through admob in android studio. I have one ad working, but I am not sure how to get the other working.
So far this is what I have for one ad in java:
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);
This works, but how would I add a second ad with the ID adView2?
Upvotes: 3
Views: 3157
Reputation: 5351
Showing two ads on the same screen at the same time is actually a violation of AdMob's policies, and could result in the suspension of your account. I would not recommend implementing an app that way.
Upvotes: 7
Reputation: 99
I figured it out now. If anyone needs help this is the code:
// Ad #1 (ID is adView)
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);
// Ad #2 (ID is adView2)
AdView adView2 = (AdView) findViewById(R.id.adView2);
AdRequest adRequest2 = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
adView2.loadAd(adRequest2);
Upvotes: 1