NOTE: You must use Android Studio Version 4.2 Beta 2 or above.

Before we create the latest Google Admob Banner Ads, first we have to set up a new project for this. So first we create a project in Android Studio Software. All steps are given below with an image for your better understanding purpose.

STEP: 01

You can click on “Create New Project” then jump next page.

STEP: 02

Now, you must choose “Empty Activity” and then click the Next button and then you can jump next screen/page.

STEP: 03

Now, you can write “Application Name“, “Package Name“, “Save Location“, “Language – JAVA“, “Minimum SDKAPI 19“. After customization of all things then you can click the Finish button. And then you can wait a few minutes while your project is Sync successfully.

STEP: 04

Double click on “manifests” folder.

STEP: 05

Add some use permission for CONNECTIVITY. means you must create an Internet permission method then your ads will show in your mobile application.

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

STEP: 06

Add Google Admob Ads meta-data to show your ads in the application. You must insert meta-data code under the application section.

<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>

STEP: 07

Now, we can add Admob ads dependency that’s why we can insert the latest Admob dependency. Now double click on Gradle Scripts and again double click on build.gradle(Module: CLICK2CODE.app) here CLICK2CODE is my project name you can click as per your project name and insert the under dependency section given below.

// GOOGLE ADMOB ADS DEPENDENCY
implementation 'com.google.android.gms:play-services-ads:19.6.0'

STEP: 08

Now, all setups will be inserted successfully then you can click the “Sync Now” button which shows the right side top corner of your project screen.

IMPLEMENT A BANNER ADS

First, you can create a banner ads space code in your activity_main.xml file that’s why we give you the complete code below. And always remember all Banner Ads code inserted under RelativeLayout further if you want to change then you can do it yourself.

IF YOU DID NOT DO YOURSELF THEN WATCH OUR VIDEO CLICK HERE.

<RelativeLayout
    android:id="@+id/bannerAdsSpace"
    android:layout_width="match_parent"
    android:gravity="center_horizontal"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true" />

Now, we create a main JAVA code to show a simple banner ad on the mobile bottom screen and one thing you should know this code is different from other banner ad codes such that DO NOT COPY THIS CODE ANYWHERE. Below code paste under onCreate method only.

BannerAdsImplementation();

Now, you can see one error when we paste the above code under the onCreate method then you can press Alt + Enter on your keyboard button and create a new method whatever shows an option in your project.

If you are not able to create yourself then you should copy the below code and paste it out of the onCreate method.

private void BannerAdsImplementation() {
View view = findViewById(R.id.bannerAdsSpace);
AdView adView = new AdView(MainActivity.this);
adView.setAdSize(AdSize.BANNER);
((RelativeLayout) view).addView(adView);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}

Now above all banner code will be implemented if you want to create a Smart Banner code then follow the below article.

IMPLEMENT A SMART BANNER ADS

Here, you can change yourself means we can change only AdSize.BANNER replaced with AdSize.SMART_BANNER only else you can be replaced with the below code in your project.

private void BannerAdsImplementation() {
View view = findViewById(R.id.bannerAdsSpace);
AdView adView = new AdView(MainActivity.this);
adView.setAdSize(AdSize.SMART_BANNER);
((RelativeLayout) view).addView(adView);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}

IMPLEMENT A LARGE BANNER ADS

Here, you can change yourself means we can change only AdSize.BANNER replaced with AdSize.LARGE_BANNER only else you can be replaced with the below code in your project.

private void BannerAdsImplementation() {
View view = findViewById(R.id.bannerAdsSpace);
AdView adView = new AdView(MainActivity.this);
adView.setAdSize(AdSize.LARGE_BANNER);
((RelativeLayout) view).addView(adView);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}

IMPLEMENT A MEDIUM RECTANGLE BANNER ADS

Here, you can change yourself means we can change only AdSize.BANNER replaced with AdSize.MEDIUM_RECTANGLE only else you can be replaced with the below code in your project.

private void BannerAdsImplementation() {
    View view = findViewById(R.id.bannerAdsSpace);
    AdView adView = new AdView(MainActivity.this);
    adView.setAdSize(AdSize.MEDIUM_RECTANGLE);
    ((RelativeLayout) view).addView(adView);
    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
}

NOW, we created all types of banner ads above code Such that still if you have any drought then watch our YouTube Video CLICK HERE.

*** THANK YOU ***


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *