Hello Developer, In this blog we will see how to integrate Bidding Admob and Facebook Audience Network ad in Android Studio java
If You did not set up mediation setting in Facebook Monetization Manager and Admob Website then Please set up the Mediation Setting by watching this video.
If you watched this Video And set up all Mediation and Bidding settings then You can now Integrate bidding in your project. Lets Start
Paste this dependencies in build.gradle(:app).
implementation 'com.google.android.gms:play-services-ads-lite:21.0.0'
implementation 'com.google.android.gms:play-services-ads:21.0.0'
implementation 'com.facebook.android:audience-network-sdk:6.11.0'
implementation 'com.google.ads.mediation:facebook:6.11.0.0'
Add this permissions in the AndroidManifest.xml File
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Now I have integrated Banner and Interstitial Ad in the project.
<?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=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:text="Show Interstitial"
android:layout_height="wrap_content"/>
</LinearLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
ads:adSize="BANNER"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adUnitId="paste_your_admob_banner_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
public class MainActivity extends AppCompatActivity {
AdView mAdView;
InterstitialAd mInterstitialAd;
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdView = findViewById(R.id.adView);
button1 = findViewById(R.id.button1);
load_Ad();
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showInterstitialAd();
}
});
}
private void load_Ad() {
MobileAds.initialize(
this,
new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
AdRequest adRequestt = new AdRequest.Builder().build();
//load banner ad
AdRequest adRequest = new AdRequest.Builder().build();
if(mAdView.getVisibility() == View.VISIBLE) {
mAdView.loadAd(adRequest);
}
//load interstitial ad
InterstitialAd.load(this,"paste_yor_admob_interstitial_id", adRequestt,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
mInterstitialAd = null;
}
});
}
private void showInterstitialAd() {
if(mInterstitialAd != null){
mInterstitialAd.show(MainActivity.this);
} else {
//Ad is not loaded
}
}
}
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="paste_yout_app_id" />
The Bidding and Mediation integrated succesfully. Now upload your project to play store and Make sure you app is approved in Meta Monetization Manager and Admob. Thank You for visiting our blog. Do not forget to subscribe our youtube chennal for getting amazing content related to Android Studio and Coding.
2 Comments
Dear brother I have done bidding the way you told but only 10℅ ads are showing Facebook audience network and 90% in admob. Please tell me solution.
ReplyDeleteThere is not any solution for this
Delete