How to Implement Unity Ads in Android Studio Projects Banner or Interstitial Ads

Hello Friends, Today I am telling you about unity ads implementation, how to implement banner ads or interstitial ads in a new android studio project, this is very simple Follow these steps and You can easily implement them in projects!

unity ads

Firstly Open the android studio project in the android studio

Go on this website:- Unity Ads Documentation

Select the Latest Release File Download

Download UnityAds.aar.zip Folder then Unzip the folder and copy the unity-ads.aar file and Android Studio Project select in Project Mode and paste under the app > libs> paste this file. If libs folder is not created in your project first create the libs Android Resources Directory then paste the file. If you do not get my point you can check my video beloved the article.

After Paste the File you go on build.gradle (app) and add this line

 //noinspection GradlePath
    implementation files('/libs/unity-ads.aar')

and click on sync project, and wait to complete this process.

How to Place Unity Banner Ads

How to Create banner ads in your android studio project so follow these steps, firstly you create a Unity Ads Account after following these processes.

If you want to create a Unity Ads Account You can Click here

XML Code for Banner Ads

I am Providing you a Sample of Banner ads Code, You can use according to your project, if you want to change in this so you can change this code,

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:id="@+id/banner_ad"
        android:gravity="center"/>

Copy this code, and paste it there, as you want to show the banner ads, this code is for the only .XML file not for java.

JAVA Code for Banner Ads

First Create a Unity ads account, copy the Game ID and Ads unit id then Replace the Game id and Ads unit id

String GameID = "4493685";
String BannerID="Banner_Android";
String InterID="Interstitial_Android";
Boolean TestMode = false/true; //(select any one. if you test then you select true)
LinearLayout bannerAd;

this code is copied and pasted into a java file before OnCreate Methode

after that, you copied and pasted it to a java file under OnCreate Methode

bannerAd=findViewById(R.id.banner_ad);
UnityAds.initialize(this,GameID,TestMode);
BannerView view = new BannerView(MainActivity.this,BannerID,new UnityBannerSize(320,50));
view.load();
bannerAd.addView(view);

Our Banner Ads is complete, you can run your project and check your ads, Your Ads is showing if you want to release file create then you change the test mode is false,

How to Place Unity Interstitial Ads

How to Place Unity Interstitial Ads so First follow these steps after you follow this steps;-

First, create a method in the OnCreate Method

loadInterstital();

after copying and pasting this code outside of the onCreate method

private void loadInterstital() {

if (UnityAds.isInitialized()){
UnityAds.load((InterID));
}else {

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
UnityAds.load(InterID);

}
}, 5000);
}
}

Your Ads is Ready for Show if you want to your ads is shown after 5 or 10 seconds so you can use this code

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
UnityAds.show(MainActivity.this,InterID);

}
}, 15000);

Your Banner or Interstitial Both ads are ready in your App

If Any problem then check my video