www.androidchunk.com

Hi Developer, Please visit www.androidchunk.com for Latest Updates. Thank you!

How to set AdMob Banner In Navigation Drawer ?

Category: Android Codez | Last Updates: 09/08/2017

In this section we are going to set AdMob banner Ad in Navigation Drawer.

Create New project 
Create New project with Navigation Drawer Activity in Android Studio.

Android Studio>>Navigation Drawer Activity>>Finish

AdMob AppId & AdUnitId
If you already have AdMob account then sign in and get App Id & AdUnitId (banner). Otherwise, create a new account and take the next steps. Or if you wish to just test this then the test app id and adUnitId provided below. Use it. You can grab more sample test ids from the official developer website



Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713

Sample Banner ad unit ID: ca-app-pub-3940256099942544/6300978111



Attention, App Id & AdUnitId are two different things. Do not get confused about it.

Import the Google Mobile Ads
First of all we have to import the Google Mobile Ads SDK into our project to enable Google AdMob Ads. Import the Google Mobile Ads SDK in the app-level build.gradle.

app/build.gradle

Set Banner In Layout

layout/activity_main.xml

Initializing & Loading Banner Ad
Using initialize static method of the MobileAds class, Initialize the Google AdMob Ads. After that we have to create a reference object of AdView class to finding our banner adView.

src/MainActivity.java

Add Internet Permission
Please wait, Add Internet permission in the AndroidManifest.


<uses-permission android:name="android.permission.INTERNET"/>


Output


Happy Coding!

No comments :

Post a Comment