First we need to add google ads library in our build.gradle file, so just copy and paste that dependency from this link. Now sync your project after that you need to add initialization of admob in your manifest. so just follow the pics and copy that tag which we need to mention in our manifest file. So first of all just open manifest and before application end tag and activity close tag we need to paste this code between these tags.
Like This👇🏼
you can get this code from android developer page from here, just replace that xxx with your admob initialise id if you want to publish app or if you just want to test ad then use google test id.After this open you xml where you want to show banner ad and paster adview layout.
Now Open that xml layout activity and get that adview id in activity by getting variable Adview with findview by id, after this we need to initialise our ad so just type
this code
or you can copy paste from google developer website click here to copy, After this you need to write two line.
code for Admob Banner ad in Java activity
- AdRequest adrequest= new AdRequest.Builder.build();
- adView.loadAd(adrequest);
So After doing these steps you banner will display in your app you can test in your device.
No comments:
Post a Comment