Banner ads are rectangular image or text ads that occupy a spot within an app’s layout. If you’re new to mobile advertising, banner ads are the easiest to implement.
This article shows you how to integrate banner ads from AdMob into an Android app.
First create a new project in Android Studio and add the following codes to import the google Mobile Ads SDK.
In the project-level build.gradle file, add the highlighted code to the allprojects section.
In the app-level build.gradle file, add the highlighted code to dependencies section.
Add the following code to Main Activity to initialize Mobile Ads SDK (this only needs to be done once in app lifecycle). You can find the App ID in AdMob console.
Add the highlighted code to activity_main.xml to show banner ad.
Add the highlighted code to Main Activity to show Banner Ad.
Add the Admob App Id and Banner Ad Id to string.xml.
- Android | AdMob Interstitial Ads for Android Studio
- Android | How to Create/Start a New Project in Android Studio?
- Toasts for Android Studio
- Guide to Install and Set up Android Studio
- 10 Important Android Studio Shortcuts You Need the Most
- How to create a Stopwatch App using Android Studio
- How to build a simple Calculator app using Android Studio?
- How to Upload Project on GitHub from Android Studio?
- How to scale different Views to all screen sizes in Android Studio?
- How to build a simple music player app using Android Studio
- Android | How to Request permissions in Android Application?
- Android | How to add Radio Buttons in an Android Application?
- Android | Android Application File Structure
- Android | Running your first Android app
- How to add ColorSeekBar in Android
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai