Banner ads Implementation | How to ad banner ad into app | Android Studio



Banner Ads Implementation Code...


XML Code... 

?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Translation">


<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView_translate"
/>

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="300dp"
android:layout_height="250dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="MEDIUM_RECTANGLE"
app:adUnitId="ca-app-pub-000000000/000000000">

</com.google.android.gms.ads.AdView>

</RelativeLayout>




Java Class Code...


private AdView mAdView;
//add coding
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
AdView adView = new AdView(this);

//ad coding starting.....

adView.setAdSize(AdSize.LARGE_BANNER);

adView.setAdUnitId("ca-app-pub-2692689882937391/8669833521");
// Add adView to your view hierarchy.

mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
super.onAdLoaded();
Toast.makeText(Translation.this,"Keep Learning",Toast.LENGTH_SHORT).show();
}

@Override
public void onAdFailedToLoad(LoadAdError adError) {
// Code to be executed when an ad request fails.
super.onAdFailedToLoad(adError);
mAdView.loadAd(adRequest);
}

@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
super.onAdOpened();
}

@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}


public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}

@Override
public void onAdClosed() {
// Code to be executed when the user is about to return
// to the app after tapping on an ad.
}
});

Paste this Above code into your onCreate method..


IF you have any problem please comment blow.



Comments

Popular posts from this blog

Click Ads Earn Money 💰 watch ads and earn $5 dollars per Ad with proof👍

All Language Translator App Android Studio Source code by ajjuvirus.inc

Kotlin coroutines on Android Step by Step Basic to advance