Rapid Subscribe Android App

Rapid Subscribe Android App
Rapid Subscriber

Recent Posts

MoPub Interstitial Ads | Earn money from MoPub Ads

MoPub Interstitial Ads | Earn Money from MoPub Ads




In this video, we will learn how to make money from MoPub Ads. If you have an Android App, and you want to make money from your Android App by placing Ads in it then create a MoPub account and earn money from your ads integration.

We will learn Integration of Banner, Interstitial and Rewarded Ads.



AppLovin MoPub Interstitial Ads preview
AppLovin MoPub Interstitial Ads preview


AppLovin MoPub Test Ad Codes from official website
FormatSizeAd unit ID
Banner320x50b195f8dd8ded45fe847ad89ed1d016da
Medium Rectangle300x250252412d5e9364a05ab77d9396346d73d
Interstitial320x48024534e1901884e398f1253216226017e
Rewarded AdN/A920b6145fb1546cf8b5cf2ac34638bb7
Rewarded PlayableN/A15173ac6d3e54c9389b9a5ddca69b34b
NativeN/A11a17b188668469fb0412708c3d16813

To start integration of AppLovin MoPub Ads, You have to add library in your app-level build.gradle

AppLovin MoPub Library
 implementation('com.mopub:mopub-sdk:5.18.0') {  //full sdk  
     transitive = true  
   }  
 //If you want to use only single ad then add only specific ad library  
 // For banners  
   implementation('com.mopub:mopub-sdk-banner:+@aar') {  
     transitive = true  
   }  
   // For fullscreen ads  
   implementation('com.mopub:mopub-sdk-fullscreen:+@aar') {  
     transitive = true  
   }  
   // For native static (images).  
   implementation('com.mopub:mopub-sdk-native-static:+@aar') {  
     transitive = true  
   }  

Then we will add a button in our XML to load our interstitial ad.

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"  
   tools:context=".MoPubAds.Mopub_Interstitial">  
   <Button  
     android:id="@+id/mopub_interstitial_button"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:text="MoPub Interstitial"  
     android:textSize="20sp"  
     android:textStyle="bold"  
     android:layout_margin="30dp"/>  
 </LinearLayout>  

Then we will initialize our AppLovin MoPub sdk then we will load interstitial Ads on button click. Also, we will load our interstitial ads after a progress dialog of 1500ms (1.5s). because of avoiding policy violation.

Java activity
 import android.app.ProgressDialog;  
 import android.os.Bundle;  
 import android.os.Handler;  
 import android.util.Log;  
 import android.view.View;  
 import android.widget.Toast;  
 import androidx.appcompat.app.AppCompatActivity;  
 import com.mopub.common.MoPub;  
 import com.mopub.common.SdkConfiguration;  
 import com.mopub.common.SdkInitializationListener;  
 import com.mopub.mobileads.MoPubErrorCode;  
 import com.mopub.mobileads.MoPubInterstitial;  
 import com.mopub.mobileads.MoPubRewardedAds;  
 import studio.harpreet.sampleproject.BuildConfig;  
 import studio.harpreet.sampleproject.R;  
 import static com.mopub.common.logging.MoPubLog.LogLevel.DEBUG;  
 import static com.mopub.common.logging.MoPubLog.LogLevel.INFO;  
 public class Mopub_Interstitial extends AppCompatActivity {  
   MoPubInterstitial interstitial;  
   String TAG = "Mopub_Interstitial";  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_mopub__interstitial);  
     final SdkConfiguration.Builder configBuilder = new SdkConfiguration.  
         Builder("24534e1901884e398f1253216226017e");  
     if (BuildConfig.DEBUG) {  
       configBuilder.withLogLevel(DEBUG);  
     } else {  
       configBuilder.withLogLevel(INFO);  
     }  
     MoPub.initializeSdk(this, configBuilder.build(), new SdkInitializationListener() {  
       @Override  
       public void onInitializationFinished() {  
       }  
     });  
     interstitial = new MoPubInterstitial(this,"24534e1901884e398f1253216226017e");  
     interstitial.load();// Multiple load called because new ad takes time to load  
               // you can load ad in onstart and show accordingly  
     findViewById(R.id.mopub_interstitial_button).setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(View view) {  
         MoPubRewardedAds.loadRewardedAd("15173ac6d3e54c9389b9a5ddca69b34b");  
         MoPubRewardedAds.showRewardedAd("15173ac6d3e54c9389b9a5ddca69b34b");  
         // Load your ads with a progress dialog of approx. 1500 ms  
         interstitial.load(); // in case failed from on create  
         if(interstitial.isReady()) // if interstitial ad is loaded and ready to shown  
         {  
           ProgressDialog dialog = new ProgressDialog(Mopub_Interstitial.this);  
           dialog.setCancelable(false);  
           dialog.setMessage("Loading an Ad...");  
           dialog.show();  
           Handler handler = new Handler();  
           handler.postDelayed(new Runnable() {  
             @Override  
             public void run() {  
               dialog.dismiss();  
               interstitial.show();  
             }  
           },1500);  
         }  
         else  
         {  
           interstitial.load();  
           Toast.makeText(Mopub_Interstitial.this, "Ad not loaded yet", Toast.LENGTH_SHORT).show();  
         }  
       }  
     });  
     interstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {  
       @Override  
       public void onInterstitialLoaded(MoPubInterstitial moPubInterstitial) {  
         Log.e(TAG, "onInterstitialLoaded: " );  
         //show ad  
       }  
       @Override  
       public void onInterstitialFailed(MoPubInterstitial moPubInterstitial, MoPubErrorCode moPubErrorCode) {  
         Log.e(TAG, "onInterstitialFailed: "+moPubErrorCode );  
       }  
       @Override  
       public void onInterstitialShown(MoPubInterstitial moPubInterstitial) {  
       }  
       @Override  
       public void onInterstitialClicked(MoPubInterstitial moPubInterstitial) {  
       }  
       @Override  
       public void onInterstitialDismissed(MoPubInterstitial moPubInterstitial) {  
         //go to next activity or give coins  
       }  
     });  
   }  
 }  



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

No comments