AppLovin MoPub Rewarded Ads | Earn Money from AppLovin MoPub Ads
MoPub Rewarded 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 Test Ad Codes from official website
Format Size Ad unit ID Banner 320x50 b195f8dd8ded45fe847ad89ed1d016da Medium Rectangle 300x250 252412d5e9364a05ab77d9396346d73d Interstitial 320x480 24534e1901884e398f1253216226017e Rewarded Ad N/A 920b6145fb1546cf8b5cf2ac34638bb7 Rewarded Playable N/A 15173ac6d3e54c9389b9a5ddca69b34b Native N/A 11a17b188668469fb0412708c3d16813
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:5.18.0') {
transitive = true
}
// For fullscreen ads
implementation('com.mopub:mopub-sdk-fullscreen:5.18.0') {
transitive = true
}
// For native static (images).
implementation('com.mopub:mopub-sdk-native-static:5.18.0') {
transitive = true
}
Then we will add a Button in our XML file to load our Rewarded Ad on a Button Click.
XML file <?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=".MoPubAds.Mopub_rewarded">
<Button
android:id="@+id/mopub_rewarded_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mopub Rewarded"
android:textStyle="bold"
android:layout_margin="30dp"
android:textSize="20sp"/>
</LinearLayout>
Then we initialize our AppLovin MoPub Sdk and load our Rewarded Ad on a Button Click. Also, because of policy violation, we will show a progress dialog of approx. 1500ms to tell user that Ad will be loaded in 1500ms.
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.MoPubReward;
import com.mopub.common.SdkConfiguration;
import com.mopub.common.SdkInitializationListener;
import com.mopub.mobileads.MoPubErrorCode;
import com.mopub.mobileads.MoPubRewardedAdListener;
import com.mopub.mobileads.MoPubRewardedAds;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
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_rewarded extends AppCompatActivity {
String adunitid = "920b6145fb1546cf8b5cf2ac34638bb7";
String TAG = "Mopub_rewarded";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mopub_rewarded);
final SdkConfiguration.Builder configBuilder = new SdkConfiguration.
Builder(adunitid);
if (BuildConfig.DEBUG) {
configBuilder.withLogLevel(DEBUG);
} else {
configBuilder.withLogLevel(INFO);
}
MoPub.initializeSdk(this, configBuilder.build(), new SdkInitializationListener() {
@Override
public void onInitializationFinished() {
}
});
MoPubRewardedAds.loadRewardedAd(adunitid);
//multiple load called because new adunits load takes time,
//Load your ad only once in onstart or load on usage..
findViewById(R.id.mopub_rewarded_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MoPubRewardedAds.loadRewardedAd(adunitid);// if ad not loaded previously
// always show after an approx. 1500ms dialog finished saying ad loaded
if(MoPubRewardedAds.hasRewardedAd(adunitid)) { //to check which adunit ad has loaded or not
ProgressDialog dialog = new ProgressDialog(Mopub_rewarded.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();
MoPubRewardedAds.showRewardedAd(adunitid);
}
}, 1500);
}
else
{
Toast.makeText(Mopub_rewarded.this, "No ad Loaded", Toast.LENGTH_SHORT).show();
//do remaining work
}
}
});
MoPubRewardedAds.setRewardedAdListener(new MoPubRewardedAdListener() {
@Override
public void onRewardedAdLoadSuccess(@NotNull String s) {
Log.e(TAG, "onRewardedAdLoadSuccess: "+s );
}
@Override
public void onRewardedAdLoadFailure(@NotNull String s, @NotNull MoPubErrorCode moPubErrorCode) {
Log.e(TAG, "onRewardedAdLoadFailure: "+moPubErrorCode );
}
@Override
public void onRewardedAdStarted(@NotNull String s) {
Log.e(TAG, "onRewardedAdStarted: "+s );
//s is adunit id to check which adunit is loaded if you have multiple
}
@Override
public void onRewardedAdShowError(@NotNull String s, @NotNull MoPubErrorCode moPubErrorCode) {
}
@Override
public void onRewardedAdClicked(@NotNull String s) {
}
@Override
public void onRewardedAdClosed(@NotNull String s) {
Log.e(TAG, "onRewardedAdClosed: "+s);
//goto next activity
}
@Override
public void onRewardedAdCompleted(@NotNull Set<String> set, @NotNull MoPubReward moPubReward) {
Log.e(TAG, "onRewardedAdCompleted: "+moPubReward );
//give coin or reward to users
//as completed and and shown close button close and goto next activity
}
});
}
}
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.
Format | Size | Ad unit ID |
---|---|---|
Banner | 320x50 | b195f8dd8ded45fe847ad89ed1d016da |
Medium Rectangle | 300x250 | 252412d5e9364a05ab77d9396346d73d |
Interstitial | 320x480 | 24534e1901884e398f1253216226017e |
Rewarded Ad | N/A | 920b6145fb1546cf8b5cf2ac34638bb7 |
Rewarded Playable | N/A | 15173ac6d3e54c9389b9a5ddca69b34b |
Native | N/A | 11a17b188668469fb0412708c3d16813 |
To start integration of AppLovin MoPub Ads, You have to add library in your app-level build.gradle
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:5.18.0') {
transitive = true
}
// For fullscreen ads
implementation('com.mopub:mopub-sdk-fullscreen:5.18.0') {
transitive = true
}
// For native static (images).
implementation('com.mopub:mopub-sdk-native-static:5.18.0') {
transitive = true
}
<?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=".MoPubAds.Mopub_rewarded">
<Button
android:id="@+id/mopub_rewarded_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mopub Rewarded"
android:textStyle="bold"
android:layout_margin="30dp"
android:textSize="20sp"/>
</LinearLayout>
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.MoPubReward;
import com.mopub.common.SdkConfiguration;
import com.mopub.common.SdkInitializationListener;
import com.mopub.mobileads.MoPubErrorCode;
import com.mopub.mobileads.MoPubRewardedAdListener;
import com.mopub.mobileads.MoPubRewardedAds;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
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_rewarded extends AppCompatActivity {
String adunitid = "920b6145fb1546cf8b5cf2ac34638bb7";
String TAG = "Mopub_rewarded";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mopub_rewarded);
final SdkConfiguration.Builder configBuilder = new SdkConfiguration.
Builder(adunitid);
if (BuildConfig.DEBUG) {
configBuilder.withLogLevel(DEBUG);
} else {
configBuilder.withLogLevel(INFO);
}
MoPub.initializeSdk(this, configBuilder.build(), new SdkInitializationListener() {
@Override
public void onInitializationFinished() {
}
});
MoPubRewardedAds.loadRewardedAd(adunitid);
//multiple load called because new adunits load takes time,
//Load your ad only once in onstart or load on usage..
findViewById(R.id.mopub_rewarded_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MoPubRewardedAds.loadRewardedAd(adunitid);// if ad not loaded previously
// always show after an approx. 1500ms dialog finished saying ad loaded
if(MoPubRewardedAds.hasRewardedAd(adunitid)) { //to check which adunit ad has loaded or not
ProgressDialog dialog = new ProgressDialog(Mopub_rewarded.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();
MoPubRewardedAds.showRewardedAd(adunitid);
}
}, 1500);
}
else
{
Toast.makeText(Mopub_rewarded.this, "No ad Loaded", Toast.LENGTH_SHORT).show();
//do remaining work
}
}
});
MoPubRewardedAds.setRewardedAdListener(new MoPubRewardedAdListener() {
@Override
public void onRewardedAdLoadSuccess(@NotNull String s) {
Log.e(TAG, "onRewardedAdLoadSuccess: "+s );
}
@Override
public void onRewardedAdLoadFailure(@NotNull String s, @NotNull MoPubErrorCode moPubErrorCode) {
Log.e(TAG, "onRewardedAdLoadFailure: "+moPubErrorCode );
}
@Override
public void onRewardedAdStarted(@NotNull String s) {
Log.e(TAG, "onRewardedAdStarted: "+s );
//s is adunit id to check which adunit is loaded if you have multiple
}
@Override
public void onRewardedAdShowError(@NotNull String s, @NotNull MoPubErrorCode moPubErrorCode) {
}
@Override
public void onRewardedAdClicked(@NotNull String s) {
}
@Override
public void onRewardedAdClosed(@NotNull String s) {
Log.e(TAG, "onRewardedAdClosed: "+s);
//goto next activity
}
@Override
public void onRewardedAdCompleted(@NotNull Set<String> set, @NotNull MoPubReward moPubReward) {
Log.e(TAG, "onRewardedAdCompleted: "+moPubReward );
//give coin or reward to users
//as completed and and shown close button close and goto next activity
}
});
}
}
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,
Subscribe to Harpreet studio on Youtube
Like Harpreet Studio on Facebook
Follow me on Instagram , Harpreet Studio on Instagram,
Install our Android app from Google Play store
No comments