Rapid Subscribe Android App

Rapid Subscribe Android App
Rapid Subscriber

Recent Posts

How to create an Interstitial Ad in Android App | Place Interstitial Ad

In our Previous Post, we create a banner Ad (Small mini Ad) placed on the bottom of the screen.

For Rewarded ad, click Here

In this post, we place an Interstitial Ad, which is a full-screen ad displayed on your smartphone.


For that, we create a new Ad unit in our Admob Account which is of Interstitial Ad and Setup it.



Interstitial Ad Setup


Add Gradle Dependency. and Application Id in AndroidManifest.xml like previous post


Then, we add a new show button in our MainActivity.xml to show Interstitial Ad on Button Click.


MainActivity.XML

 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:app="http://schemas.android.com/apk/res-auto"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   android:orientation="vertical"  
   tools:context=".MainActivity">  
   <TextView  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="Hello World!"  
     app:layout_constraintBottom_toBottomOf="parent"  
     app:layout_constraintLeft_toLeftOf="parent"  
     app:layout_constraintRight_toRightOf="parent"  
     app:layout_constraintTop_toTopOf="parent" />  
   <Button  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="Show Interstitial"  
     android:id="@+id/AdButton">  
   </Button>  
 </LinearLayout>  

 Then we add a click listener on Button and setup Interstitial Ad inside Click Listener. Also, we add our Add unit Id in string resources.


MainActivity.java

 public class MainActivity extends AppCompatActivity {  
   Button btn;  
   InterstitialAd minterstitialad;  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
     btn = findViewById(R.id.AdButton);  
     minterstitialad = new InterstitialAd(this);  
     btn.setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(View v) {  
         minterstitialad.setAdUnitId(getstring(R.string.InterstitialAdId);  
         AdRequest adRequest1 = new AdRequest.Builder().addTestDevice("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").build();  
         minterstitialad.loadAd(adRequest1);  
       }  
     });  
     minterstitialad.setAdListener(new AdListener()  
     {  
       public void onAdLoaded() {  
         if(minterstitialad.isLoaded())  
         {  
           minterstitialad.show();  
         }  
       }  
     });  
   }  

Now, we Successfully load Full-Screen ad on Button click.

To create Banner Ad
To create Rewarded Ad

Follow us for more posts like this, 
Subscribe Harpreet studio on Youtube  
Like Harpreet Studio on Facebook  
Follow me on Instagram 

1 comment: