How to insert AdMob Banner Ad in your Android App | Techvaccine | Google Admob

How to insert AdMob Banner Ad in your Android App | Techvaccine | Google Admob



In this article, I will show you how to insert banner ad code in your Android application. Before I give you a brief idea of ​​what a banner ad is.

Banner advertising is one of AdMob's ad types that gives you through the revenue generated by displaying ads on your app. To know more about AdMob and Banner Ad, click on the link below.

What is AdMob and how to generate ad unit ID?
There are four types of AdMob Ads through which you can make money. You can click on the link below to learn more about other types of AdMob ads.

banner ad
Native advertising
Reward advertising
Interstitial advertisement
Now, let's start with how to put the code of banner ads in your Android application. I have assumed that you are using Android Studio to develop your app and opened your project in it. Follow the steps given below and copy the code in your project carefully.

⟩⟩ First you need to add below the line of code to your build.gradle dependency file.

Compilation 'com.google.android.gms: play-services-ads: 8.4.0'
After adding the above code you will get a sync option in the top right corner of the page. Click on it and wait a few minutes to complete the process, once the gradle building is finished you are ready to go on with the next steps.

⟩⟩ Then open the manifest file and add Internet permission to it.

<Use-permission android: name = "android.permission.INTERNET" />
. In the project structure, go to activity_main.xml and paste the following code in your layout.

<com.google.android.gms.ads.AdView
Android: id = "@ + id / adview"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_centerHorizontal = "true"
Android: layout_alignParentBottom = "true"
Advertisement: adSize = "Banner"
Advertisement: adUnitId = "@ string / banner_ad_unit_id">
</Com.google.android.gms.ads.AdView>
And add below the lines of code in the same file i.e activity_main.xml header part

xmlns: ad = "http://schemas.android.com/apk/res-auto"
⟩⟩ Now open MainActivity.java and add below the lines of code in the onCreate method

AdView mAdView = (AdView) findViewById (R.id.adView);
AdRequest adRequest = new AdRequest.Builder (). Build ();
mAdView.loadAd (adRequest);
⟩⟩ Now open the string.xml file in the values ​​folder and paste the bottom line of code.

CA, App Pub-39402560999 xxxxx / 63009xxxxx
Here is a sample ID using the banner AdMob ID. To get revenue, you have to replace this test ID with your own banner ad ID. If you do not know how to get your banner ad id then how to get banner ad unit id, click here.

Note: Do not use your actual ad unit ID when testing and never click on your ad. It is against AdMob policy.

That is, friends, this is the perfect and simple way to insert banner ads in your application. Just follow the steps above and carefully paste the code in the correct place as stated above.

If you are a beginner, you will love learning Android application development from scratch.

If you found this article useful, please comment below and share the article to support me. If you have any suggestions, please feel free to comment below.

Post a Comment

0 Comments