AppLovin MoPub Banner Ads | Earn Money from AppLovin MoPub Ads
MoPub Banner 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 Banner Ad Preview |
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 add ad code in your XML file
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=".MoPubAds.MoPub_Banner">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mo Pub banner"
android:textStyle="bold"
android:textSize="20sp"
android:layout_margin="30dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="bottom">
<com.mopub.mobileads.MoPubView
android:id="@+id/mopub_banner_view"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:moPubAdSize="height_50">
</com.mopub.mobileads.MoPubView>
</LinearLayout>
</LinearLayout>
Then In your JAVA file, initialize AppLovin MoPub Sdk and load your ad, we will also add listener to banner ads to check when our ad is loaded or if an error occurs.
Your Newly generated AdCode will takes time to load on first time. See your Logcat for error of more reference about loading your ads.
Java File
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
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.MoPubView;
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_Banner extends AppCompatActivity {
private MoPubView moPubView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mo_pub__banner);
final SdkConfiguration.Builder configBuilder = new SdkConfiguration.Builder(getString(R.string.mopub_banner));
if (BuildConfig.DEBUG) {
configBuilder.withLogLevel(DEBUG);
} else {
configBuilder.withLogLevel(INFO);
}
MoPub.initializeSdk(this, configBuilder.build(), new SdkInitializationListener() {
@Override
public void onInitializationFinished() {
}
});
moPubView = (MoPubView) findViewById(R.id.mopub_banner_view);
moPubView.setAdUnitId(getString(R.string.mopub_banner)); // Enter your Ad Unit ID from www.mopub.com
// moPubView.setAdSize(MoPubAdSize); // Call this if you are not setting the ad size in XML or wish to use an ad size other than what has been set in the XML. Note that multiple calls to `setAdSize()` will override one another, and the MoPub SDK only considers the most recent one.
// moPubView.loadAd(MoPubAdSize); // Call this if you are not calling setAdSize() or setting the size in XML, or if you are using the ad size that has not already been set through either setAdSize() or in the XML
moPubView.loadAd();
moPubView.setBannerAdListener(new MoPubView.BannerAdListener() {
@Override
public void onBannerLoaded(@NonNull MoPubView moPubView) {
Log.e("TAG", "onBannerLoaded: " );
}
@Override
public void onBannerFailed(MoPubView moPubView, MoPubErrorCode moPubErrorCode) {
Log.e("TAG", "onBannerFailed: "+moPubErrorCode );
}
@Override
public void onBannerClicked(MoPubView moPubView) {
}
@Override
public void onBannerExpanded(MoPubView moPubView) {
}
@Override
public void onBannerCollapsed(MoPubView moPubView) {
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
moPubView.destroy();
}
}
MoPub Interstitial Ads | Earn Money from Interstitial Ads
MoPub Rewarded Ads | Earn Money from Interstitial Ads
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