How to create Banner ads in android studio || Smart Banner Ads || Medium Rectangle Banner Ads – CLICK2CODE

0 Comments


Step: 1

First, we create a new project and if you have an existing project whatever you created then you can start to implement code in your project.

Step: 2

Now you can implement SDK integration means dependency on your project and go to build.gradle(Module: app) under Gradle Script Files. The code is given below.

implementation 'com.google.android.gms:play-services-ads:19.1.0'

Step: 3

After that, you can integrate APP ID in your Manifest.xml file under manifests code given below.

<meta-data

   android:name="com.google.android.gms.ads.APPLICATION_ID"

   android:value="ca-app-pub-3940256099942544~3347511713" />

Step: 4

Now you can give permission for the INTERNET then you can able to show ads in your android apps.

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

Step: 5

  • Now you can create BANNER ADS code in your activity.xml in your project.
    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
       android:id="@+id/adView"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:layout_centerHorizontal="true"
       ads:adSize="BANNER"
       ads:adUnitId="@string/bannerAds"/>
  • Now you can create SMART_BANNER ADS code in your activity.xml in your project.
      <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
      android:id="@+id/adView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      ads:adSize="SMART_BANNER"
      ads:adUnitId="@string/bannerAds"/>

Step: 6

Now you can implement code in JAVA files in your Activity on your project.

MobileAds.initialize(this, new OnInitializationCompleteListener() {
      @Override
      public void onInitializationComplete(InitializationStatus initializationStatus) {
      }
});
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

Step: 7

At the end, you can add a banner id in your string.xml file under the vales folder. The code is given below.

<string name="bannerAds">ca-app-pub-3940256099942544/6300978111</string>
NOTE: TEST APP ID AND UNIT ID ONLY FOR TESTING PURPOSE. IF YOU WANT to PUBLISH YOUR APP ON GOOGLE PLAY-STORE THEN YOU MUST REPLACE REAL APP ID AND UNIT ID.

Now you implemented all code in your codes and RUN your project in your real device. If you can not understand then you must visit our YouTube Channel Videos.

share this

Leave a Reply

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