How to Implement AppLovin Banner Ads Android Studio

How to Implement AppLovin Banner Ads Android Studio

how to implement Applovin Banner ads , in this article i will tell you complete process please complete follow this article aut watch video. Applovin Banner implementation i used android studio, you can download android studio simply type download android studio in google and download android studio after this open android studio create new project gave name, and select empty activity, all these steps are in video,  i can past here only android and java code, you can simply copy and past these code to your project and enjoy app lovin banner ads,


How to Implement AppLovin Banner Ads Android Studio
How to Implement AppLovin Banner Ads Android Studio

1.Ad these dependances in  your project:

implementation "com.android.support:support-v13:${versions.supportLibrary}"implementation "com.android.support:recyclerview-v7:${versions.supportLibrary}"implementation "com.google.android.gms:play-services-ads:${versions.playServicesAds}"if (new File(projectDir, "../../Android-SDK").exists()) {
    implementation project(':Android-SDK')
}
// Otherwise (AppLovin Demo app is running as a standalone project) - Import latest AppLovin SDK from JCenterelse {
    implementation "com.applovin:applovin-sdk:+"}
and sync now this project

 2.Now Past these permission into the manifest and also past applovin sdk

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission    android:name="android.permission.WRITE_EXTERNAL_STORAGE"    android:maxSdkVersion="18" />

<!-- These permissions are strongly recommended and will result in higher performance --><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 
past applovin sdk under <application>
 
<meta-data    android:name="applovin.sdk.key"    android:value=" past your aplovin sdk key here" /> 
 
<application/> 



App Lovin Activity Main Xml Code :

simply follow video for complete guide, copy this code and past it into your project ,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.junaid.apps.earnreward.banners.BannerLayoutEditorActivity">

    <!-- To automatically load an ad, add the next the next two lines into the <com.applovin.adview.AppLovinAdView> element -->
    <!--xmlns:demo="http://schemas.applovin.com/android/1.0"-->
    <!--demo:loadAdOnCreate="true"-->

   

    <com.applovin.adview.AppLovinAdView
        android:id="@+id/ad_view"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:id="@+id/status_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:text="Ready to load ads."
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/load_button"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_above="@+id/ad_view"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:background="@android:color/transparent"
        android:text="Load"
        android:textAllCaps="false"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#0A83AA" />

</RelativeLayout>



Copy This Java Code and past into Activity Main:

public final class BannerLayoutEditorActivity
        extends AdStatusActivity
{
    @Override
    protected void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_banner_layout_editor );

        adStatusTextView = (TextView) findViewById( R.id.status_label );

        // Retrieve banner from layout editor
        final AppLovinAdView adView = (AppLovinAdView) findViewById( R.id.ad_view );


        final Button loadButton = (Button) findViewById( R.id.load_button );

        loadButton.setOnClickListener( new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                adView.loadNextAd();
            }
        } );

        //
        // Optional: Set listeners
        //
        adView.setAdLoadListener( new AppLovinAdLoadListener()
    {
        @Override
        public void adReceived(final AppLovinAd ad)
        {
            log( "Banner loaded" );
        }

        @Override
        public void failedToReceiveAd(final int errorCode)
        {
            // Look at AppLovinErrorCodes.java for list of error codes
            log( "Banner failed to load with error code " + errorCode );
        }
    } );

        adView.setAdDisplayListener( new AppLovinAdDisplayListener()
        {
            @Override
            public void adDisplayed(final AppLovinAd ad)
            {
                log( "Banner Displayed" );
            }

            @Override
            public void adHidden(final AppLovinAd ad)
            {
                log( "Banner Hidden" );
            }
        } );

        adView.setAdClickListener( new AppLovinAdClickListener()
        {
            @Override
            public void adClicked(final AppLovinAd ad)
            {
                log( "Banner Clicked" );
            }
        } );

        adView.setAdViewEventListener( new AppLovinAdViewEventListener()
        {
            @Override
            public void adOpenedFullscreen(final AppLovinAd ad, final AppLovinAdView adView)
            {
                log( "Banner opened fullscreen" );
            }

            @Override
            public void adClosedFullscreen(final AppLovinAd ad, final AppLovinAdView adView)
            {
                log( "Banner closed fullscreen" );
            }

            @Override
            public void adLeftApplication(final AppLovinAd ad, final AppLovinAdView adView)
            {
                log( "Banner left application" );
            }

            @Override
            public void adFailedToDisplay(final AppLovinAd ad, final AppLovinAdView adView, final AppLovinAdViewDisplayErrorCode code)
            {
                log( "Banner failed to display with error code " + code );
            }
        } );

        // Load an ad!
        adView.loadNextAd();

        adView.setAdLoadListener( new AppLovinAdLoadListener()
        {
            @Override
            public void adReceived(final AppLovinAd ad)
            {
                log( "Banner loaded" );
            }

            @Override
            public void failedToReceiveAd(final int errorCode)
            {
                // Look at AppLovinErrorCodes.java for list of error codes
                log( "Banner failed to load with error code " + errorCode );
            }
        } );

        adView.setAdDisplayListener( new AppLovinAdDisplayListener()
        {
            @Override
            public void adDisplayed(final AppLovinAd ad)
            {
                log( "Banner Displayed" );
            }

            @Override
            public void adHidden(final AppLovinAd ad)
            {
                log( "Banner Hidden" );
            }
        } );

        adView.setAdClickListener( new AppLovinAdClickListener()
        {
            @Override
            public void adClicked(final AppLovinAd ad)
            {
                log( "Banner Clicked" );
            }
        } );


        //
        // Please note that the AppLovinAdView CAN AUTOMATICALLY invoke loadNextAd() upon inflation from layout
        // To do so, add the following attributes to the com.applovin.adview.AppLovinAdView element:
        //
        // xmlns:demo="http://schemas.applovin.com/android/1.0"
        // demo:loadAdOnCreate="true"
        //
    }
}


Now Create a New Empty Activty Game Name BannerActivity:

Now past below code into the Java Activity:

 

 

public final class BannerProgrammaticActivity
        extends AdStatusActivity
{
    @Override
    protected void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_banner_programmatic );

        adStatusTextView = (TextView) findViewById( R.id.status_label );

        final AppLovinAdView adView = new AppLovinAdView( AppLovinAdSize.BANNER, this );

        Button loadButton = (Button) findViewById( R.id.load_button );

        loadButton.setOnClickListener( new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                adView.loadNextAd();

            }
        } );

        //
        // Optional: Set listeners
        //
        adView.setAdLoadListener( new AppLovinAdLoadListener()
        {
            @Override
            public void adReceived(final AppLovinAd ad)
            {
                log( "Banner loaded" );
            }

            @Override
            public void failedToReceiveAd(final int errorCode)
            {
                // Look at AppLovinErrorCodes.java for list of error codes
                log( "Banner failed to load with error code " + errorCode );
            }
        } );

        adView.setAdDisplayListener( new AppLovinAdDisplayListener()
        {
            @Override
            public void adDisplayed(final AppLovinAd ad)
            {
                log( "Banner Displayed" );
            }

            @Override
            public void adHidden(final AppLovinAd ad)
            {
                log( "Banner Hidden" );
            }
        } );

        adView.setAdClickListener( new AppLovinAdClickListener()
        {
            @Override
            public void adClicked(final AppLovinAd ad)
            {
                log( "Banner Clicked" );
            }
        } );

        adView.setAdViewEventListener( new AppLovinAdViewEventListener()
        {
            @Override
            public void adOpenedFullscreen(final AppLovinAd ad, final AppLovinAdView adView)
            {
                log( "Banner opened fullscreen" );
            }

            @Override
            public void adClosedFullscreen(final AppLovinAd ad, final AppLovinAdView adView)
            {
                log( "Banner closed fullscreen" );
            }

            @Override
            public void adLeftApplication(final AppLovinAd ad, final AppLovinAdView adView)
            {
                log( "Banner left application" );
            }

            @Override
            public void adFailedToDisplay(final AppLovinAd ad, final AppLovinAdView adView, final AppLovinAdViewDisplayErrorCode code)
            {
                log( "Banner failed to display with error code " + code );
            }
        } );

        // Add programmatically created banner into our container
        final LinearLayout bannerContainer = (LinearLayout) findViewById( R.id.banner_container );
        bannerContainer.addView( adView, new android.widget.FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER ) );

        // Load an ad!
        adView.loadNextAd();

    }
}


Now Past Below Code into the Banner Ads Xml ActivityBannerads:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.junaid.apps.earnreward.banners.BannerProgrammaticActivity">

   

    <TextView
        android:id="@+id/status_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:text="Ready to load ads."
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:id="@+id/banner_container"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="0dp"
        android:layout_marginLeft="0dp"
        android:layout_marginBottom="0dp"
        android:orientation="vertical"></LinearLayout>

    <Button
        android:id="@+id/load_button"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_above="@+id/banner_container"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:background="@android:color/transparent"
        android:text="Load"
        android:textAllCaps="false"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#0A83AA" />

</RelativeLayout>

 
 

 

Now Create A New Class:

Game Name MenuActivity and past this code in that class

 

public class BannerDemoMenuActivity
        extends DemoMenuActivity
{
    @Override    protected DemoMenuItem[] getListViewContents()
    {
        DemoMenuItem[] result = {
                new DemoMenuItem( "Programmatic", "Programmatically creating an instance of it", new Intent( this, BannerProgrammaticActivity.class ) ),
                new DemoMenuItem( "Layout Editor", "Create a banner from the layout editor", new Intent( this, BannerLayoutEditorActivity.class ) ),
                new DemoMenuItem( "Zone Integration", "Create different user experiences of the same ad type", new Intent( this, BannerZoneActivity.class ) ),
        };
        return result;
    }
}
 
 

Now Goto Manifest and Past gave these permissions:

 

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="18" />

    <!-- These permissions are strongly recommended and will result in higher performance -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

 

and also post your applovin sdk

 

<meta-data
            android:name="applovin.sdk.key"
            android:value="_ShOfQ7IsAt-TOeMkQ-RTKCG1WDbTseyoI87H50kN2ndV4cE_fwmwba6dEb0MUH7WqDATv2tLJGWlLwnwHf5Wm" />

 

past this code in build.gradle (module)

 

 

 

 apply plugin: 'com.android.application'

buildscript {
    if (!project.hasProperty('versions')) {
        ext.versions = [
                'compileSdk'       : 27,
                'targetSdk'        : 27,
                'minSdk'           : 16,
                'supportLibrary'   : "27.1.1",
                'playServicesAds'  : "15.0.1",
                'multiDex'         : "1.0.3"
        ]
    }

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

android {
    compileSdkVersion versions.compileSdk
    defaultConfig {
        applicationId "com.junaid.apps.earnreward"
        minSdkVersion versions.minSdk
        targetSdkVersion versions.targetSdk
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
}

dependencies {
    implementation fileTree(include: ["*.jar"], dir: "libs")

    implementation "com.android.support:multidex:${versions.multiDex}"

    implementation "com.android.support:appcompat-v7:${versions.supportLibrary}"
    implementation "com.android.support:support-v13:${versions.supportLibrary}"
    implementation "com.android.support:recyclerview-v7:${versions.supportLibrary}"

    // For AppLovin SDK
    implementation "com.google.android.gms:play-services-ads:${versions.playServicesAds}"

    // If AppLovin Demo App is running as a module in the AppLovin development environment
    if (new File(projectDir, "../../Android-SDK").exists()) {
        implementation project(':Android-SDK')
    }
    // Otherwise (AppLovin Demo app is running as a standalone project) - Import latest AppLovin SDK from JCenter
    else {
        implementation "com.applovin:applovin-sdk:+"
    }
}

 


 

 

 

 

Previous
Next Post »