Implement Bidding with Partner Mediation in your Android App

This guide shows you how to add a banner ad to your app using Facebook Audience Network and a mediation partner.

Facebook App Dashboard

  1. Create a new Facebook App for your app. This will give you a Facebook App ID that represents your app.
  2. Add a Verified Business to your app. You will use this business to get a System User Access Token needed for the secure connection between Facebook and Google.
  3. Add the Audience Network Product to your app. This will take you to the Facebook Monetization Manager.

Facebook Monetization Manager Dashboard

  1. In the left navigation, go to Integration > Properties
  2. Click Create Property and Create Ad Space, and add a name and platform (android app) and click the Create button
  3. In the Ad Space create a placement
  4. Give the placement name for your ad type
  5. Under the Get code dropdown get the Placement ID to be used in the mediation partner dashboard.

Facebook Business Settings Dashboard

  1. Get a System User Access Token by navigating to System Users in the left side navigation.
  2. Assign a new asset, your app, to your system user by clicking Add Asset
  3. In the popup window, click Apps > your app > type of access ( Develop app under Standard Access or Manage app under Admin Access). Save Changes.
  4. Click Generate New Token.
  5. In the popup select your app and add read_audience_network_insights and click Generate Token.
  6. Copy and save this token. Once you close the popup, you will not be able to retrieve this token.

Connect with Mediation Partners

For a list of our mediation partners, see the Bidding with Partner Mediation overview.

Implement FB and Google SDKs in Code

  1. In your project’s build.gradle file add `mavenCentral()` to the buildscript repositories
  2. In the app's build.gradle file add the mediation provider SDKs, for example, Google, and the Facebook SDK.
    //Google Ads SDK
    implementation ''
    //Google Ads Mediation SDK for Facebook
    implementation ''
    //Facebook Audience Network SDK
    implementation '' File

  1. In MainActivity class add:
    //Will build the ad
    private AdView mAdView;  
    //Your Google Admod App ID 
    private static final String ADMOD_APP_ID = "ca-app-pub-6562014297208404~1337910868";
  2. In onCreate function add:
    //Initialize Facebook Audience Network Ads
    //Initialize Google Mobile Ads
    MobileAds.initialize(this, ADMOD_APP_ID);
    //Create the ad (This example is a banner ad)
    AdView adView = new AdView(this);
    adView.setAdUnitId("ca-app-pub-6562014297208404/1220388576");  //Your Google Ad Unit ID (For test ads, use Google’s sample Ad Unit ID)
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
       public void onInitializationComplete(InitializationStatus initializationStatus) {
    mAdView = findViewById(;
    AdRequest adRequest = new AdRequest.Builder().build();

Activity_main.xml File

Add the code to create the ad element.

<LinearLayout xmlns:android = ""
   android:id = "@+id/parent"
   xmlns:tools = ""
   android:layout_width = "match_parent"
   android:layout_height = "match_parent"
   tools:context = ".MainActivity"
   android:gravity = "center"
   android:orientation = "vertical">
       android:id = "@+id/text"
       android:textSize = "28sp"
       android:textAlignment = "center"
       android:layout_width = "match_parent"
       android:layout_height = "wrap_content" />


Network_security_config.xml File

To allow the connection to Facebook, we need to create a security xml file.

In the MyProject > app > src > main > res, create a new XML folder. In the new XML folder create an XML file named network_security_config.xml and add:

<?xml version="1.0" encoding="utf-8"?>

   <domain-config cleartextTrafficPermitted="true">
       <domain includeSubdomains="true"></domain>


AndroidManifest.xml File

Within the application manifest, add a meta-data tag for your google application ID and a meta-data tag for your Facebook app ID.

<application .../>