How to Integrate Facebook Audience Network (FAN) Rewarded Video Ads in Android?
Last Updated :
13 Aug, 2024
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating a third party advertisement e.g known as Facebook Audience Network (FAN). Facebook Audience Network is designed to help monetize with the user experience in mind. By using high-value formats, quality ads, and innovative publisher tools it helps to grow the business while keeping people engaged.
Why Facebook Audience Network?
- Facebook Audience Network is one of the best alternatives for Google Admob to monetize the Android or IOS App.
- Minimum Payout is $100
- Wide Range of Ad Formats
- Maximum Fill Rates
- High eCPM(Effective Cost Per Mille)
- Quality Ads
- Personalized Ads
Formats of Facebook Audience Network
There are mainly five types of flexible, high-performing format available in Facebook Audience Network
- Native: Ads that you design to fit the app, seamlessly
- Interstitial: Full-screen ads that capture attention and become part of the experience.
- Banner: Traditional formats in a variety of placements.
- Rewarded Video: An immersive, user-initiated video ad that rewards users for watching.
- Playables: A try-before-you-buy ad experience allowing users to preview a game before installing.
In this article let’s integrate Facebook Audience Network Rewarded Video ads in the Android app.
Rewarded Video:
- A rewarded video ad is a full-screen ad that covers the whole UI of the app. The eCPM (Effective Cost Per Mille) of Rewarded Video ads are relatively higher than banner and Interstitial ads and also leads to higher CTR(Click Through Rate) which results in more earning from the app.
- The user gets an in-App reward when they watch the Rewarded Video from start to end.
Approach
Step 1: Creating a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that choose Java as language though we are going to implement this project in Java language.
Step 2: Before going to the coding section first do some pre-task
- Go to app -> res -> values -> colors.xml file and set the colors for the app.
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#0F9D58</color>
<color name="colorPrimaryDark">#0F9D58</color>
<color name="colorAccent">#05af9b</color>
</resources>
- Go to Gradle Scripts -> build.gradle (Module: app) section and import following dependencies and click the “sync now” on the above pop up.
implementation ‘com.facebook.android:audience-network-sdk:5.+’
<uses-permission android:name=”android.permission.INTERNET”/>
Step 3: Designing the UI
In the activity_main.xml file add only one Button, so whenever the user clicks the Button the Rewarded video ad will be played.
activity_main.xml
<?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=".MainActivity">
<!-- Button to Show Rewarded Video Ad By Clicking it -->
<Button
android:id="@+id/showVideoBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="8dp"
android:background="@color/colorPrimary"
android:padding="16dp"
android:text="Show Rewarded Video Ad "
android:textColor="#ffff"
android:textSize="20dp" />
</RelativeLayout>
Step 4: Working with MainActivity.java file
- Open the MainActivity.java file there within the class, first create the object of the Button class.
// Creating an object of Button class
Button showVideoAdBtn;
- Now inside the onCreate() method, link those objects with their respective IDs that are given in activity_main.xml file.
// link those objects with their respective id’s that we have given in activity_main.xml file
showVideoAdBtn = (Button) findViewById(R.id.showVideoBtn);
- Now inside onCreate() method, initialize the Facebook Audience Network SDK
// initializing the Audience Network SDK
AudienceNetworkAds.initialize(this);
- Create an object of RewardedVideoAd inside MainActivity.java class
// creating object of RewardedVideoAd
private RewardedVideoAd fbRewardedVideoAd;
- Next create a private void loadRewardedVideoAd() method outside onCreate() method and define it.
void loadRewardedVideoAd()
{
// initializing RewardedVideoAd Object
// RewardedVideoAd Constructor Takes 2 Arguments
// 1)Context
// 2)Placement Id
fbRewardedVideoAd = new RewardedVideoAd(this, “YOUR_PLACEMENT_ID”);
// loading Ad
fbRewardedVideoAd.loadAd();
}
- Call the loadRewardedVideoAd() inside oncreate() method after initializing the SDK
Note: Replace “YOUR_PLACEMENT_ID” with your own placement id to show real ads.
- Next create a void showRewardedVideoAd() method outside onCreate() method which we call later to show ad.
public void showRewardedVideoAd()
{
// Checking If Ad is Loaded or Not
if(fbRewardedVideoAd.isAdLoaded())
{
// showing Video Ad
fbRewardedVideoAd.show();
}
else
{
// Loading Video Ad If it is Not Loaded
fbRewardedVideoAd.loadAd();
}
}
- The next thing is to call the showRewardedVideoAd() method when a user clicks a show ad button.
- Now in oncreate() method create a ClickListener for the button and call showRewardedVideoAd()
// click listener to show Rewarded Video Ad
showVideoAdBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showRewardedVideoAd();
}
});
- Now we add RewardedVideoAdListener for Rewarded Video Ad, so that users will know the status of the ads.
- To add RewardedVideoAdListener open loadRewardedVideoAd() method and add the below code before fbRewardedVideoAd.loadAd();
// RewardedVideoAd AdListener
fbRewardedVideoAd.setAdListener(new RewardedVideoAdListener() {
@Override
public void onError(Ad ad, AdError error) {
// Showing Toast Message
Toast.makeText(MainActivity.this, “onError”, Toast.LENGTH_SHORT).show();
}
@Override
public void onAdLoaded(Ad ad) {
// Showing Toast Message
Toast.makeText(MainActivity.this, “onAdLoaded”, Toast.LENGTH_SHORT).show();
}
@Override
public void onAdClicked(Ad ad) {
// Showing Toast Message
Toast.makeText(MainActivity.this, “onAdClicked”, Toast.LENGTH_SHORT).show();
}
@Override
public void onLoggingImpression(Ad ad) {
// Showing Toast Message
Toast.makeText(MainActivity.this, “onLoggingImpression”, Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoCompleted() {
// Showing Toast Message
Toast.makeText(MainActivity.this, “onRewardedVideoCompleted”, Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoClosed() {
// Showing Toast Message
Toast.makeText(MainActivity.this, “onRewardedVideoClosed”, Toast.LENGTH_SHORT).show();
}
});
- And inside RewardedVideoAdListener Override methods show a toast message so that users know the status of the ad. Below is the complete code for the MainActivity.java file.
MainActivity.java
package org.geeksforgeeks.project;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.facebook.ads.Ad;
import com.facebook.ads.AdError;
import com.facebook.ads.AudienceNetworkAds;
import com.facebook.ads.RewardedVideoAd;
import com.facebook.ads.RewardedVideoAdListener;
public class MainActivity extends AppCompatActivity {
// Creating a object of Button class
Button showVideoAdBtn;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// link those objects with their respective id's
// that we have given in activity_main.xml file
showVideoAdBtn
= (Button)findViewById(R.id.showVideoBtn);
// initializing the Audience Network SDK
AudienceNetworkAds.initialize(this);
// initializing and loading rewarded video ad
loadRewardedVideoAd();
// click listener to show Rewarded Video Ad
showVideoAdBtn.setOnClickListener(
new View.OnClickListener() {
@Override public void onClick(View view)
{
showRewardedVideoAd();
}
});
}
// creating object of RewardedVideoAd
private RewardedVideoAd fbRewardedVideoAd;
void loadRewardedVideoAd()
{
// initializing RewardedVideoAd Object
// RewardedVideoAd Constructor Takes 2 Arguments
// 1)Context
// 2)Placement Id
fbRewardedVideoAd = new RewardedVideoAd(
this, "YOUR_PLACEMENT_ID");
// RewardedVideoAd AdListener
fbRewardedVideoAd.setAdListener(
new RewardedVideoAdListener() {
@Override
public void onError(Ad ad, AdError error)
{
// Showing Toast Message
Toast
.makeText(MainActivity.this,
"onError",
Toast.LENGTH_SHORT)
.show();
}
@Override public void onAdLoaded(Ad ad)
{
// Showing Toast Message
Toast
.makeText(MainActivity.this,
"onAdLoaded",
Toast.LENGTH_SHORT)
.show();
}
@Override public void onAdClicked(Ad ad)
{
// Showing Toast Message
Toast
.makeText(MainActivity.this,
"onAdClicked",
Toast.LENGTH_SHORT)
.show();
}
@Override
public void onLoggingImpression(Ad ad)
{
// Showing Toast Message
Toast
.makeText(MainActivity.this,
"onLoggingImpression",
Toast.LENGTH_SHORT)
.show();
}
@Override
public void onRewardedVideoCompleted()
{
// Showing Toast Message
Toast
.makeText(
MainActivity.this,
"onRewardedVideoCompleted",
Toast.LENGTH_SHORT)
.show();
}
@Override
public void onRewardedVideoClosed()
{
// Showing Toast Message
Toast
.makeText(MainActivity.this,
"onRewardedVideoClosed",
Toast.LENGTH_SHORT)
.show();
}
});
// loading Ad
fbRewardedVideoAd.loadAd();
}
public void showRewardedVideoAd()
{
// Checking If Ad is Loaded
// or Not
if (fbRewardedVideoAd.isAdLoaded()) {
// showing Video Ad
fbRewardedVideoAd.show();
}
else {
// Loading Video Ad If it is Not Loaded
fbRewardedVideoAd.loadAd();
}
}
}
Output: Run on Emulator
Similar Reads
How to Integrate Facebook Audience Network (FAN) Rewarded Video Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating a third party advertisement e.g known as Facebook Audience Network (
6 min read
How to Integrate Facebook Audience Network (FAN) Banner Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating a third party advertisement e.g known as Facebook Audience Network (
7 min read
How to Integrate Facebook Audience Network (FAN) Native Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating a third-party advertisement e.g known as Facebook Audience Network (
9 min read
How to Integrate Facebook Audience Network (FAN) Interstitial Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating a third party advertisement e.g known as Facebook Audience Network (
6 min read
How to Integrate Google Admob Rewarded Video Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-app purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating an advertisement e.g. known as Google AdMob. Google AdMob is designe
7 min read
Integrate Google Admob Rewarded Video Ads in Android using Kotlin
There are many ways with the help of which we can earn money from our android applications such as by selling products or services inside our applications or by displaying ads. There are several types of ads that we can display within our application to earn money. The several types of ads consist o
4 min read
How to Create Swipeable Videos Like Instagram Reels in Android?
As we know Swipeable Videos are being used in many social media platforms apps Like Youtube Shorts, Instagram Reels, etc. In this article, we are going to implement that only in an easy and informative way, we can add as many videos. It can be done in several different ways but today we are going to
5 min read
How to Build a Facebook Like Custom RecyclerView in Android?
We have seen implementing RecyclerView in Android with simple data inside our app. In this article, we will take a look at the implementation of Facebook like Custom RecyclerView in Android. What we are going to build in this article? We will be building a simple application in which we will display
9 min read
How to Pass Video Using Intent Between Activities in Android?
In android, An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstrac
4 min read
How to Create Video Player and Downloader App in Android?
In this article, we will walk you through the process of creating a simple video player and downloader app in Android using Kotlin and Android Studio. In this project, we will use firebase to store videos and generate URLs. A sample video is given below to get an idea about what we are going to do i
3 min read
How to add Rate the App feature in Android
When you publish your app on google play store it is important to get feedback from the user. Unless the user does not love or hate your app, they are not likely to go out of their way to rate your app. Since high rating indicates the success of your app, and even criticism is required to make the a
2 min read
How to Create a Dynamic Video Player in Android with Firebase Realtime Database?
Most of the apps use the video player to display so many videos inside their application. So for playing the video the app plays the video from its video URL. But what if we want to update that video on a real-time basis. So, in that case, we have to update our database and then later on we have to
8 min read
How to Build a Video Calling Android App with Jitsi Meet SDK?
Video Calling has become a most demanding feature in many social media apps like WhatsApp, Instagram, Facebook, etc. Not only this but also there are some other applications available for providing only this feature to connect people all over the world with each other like Duo. Hence, this gives us
4 min read
Complete guide on How to build a Video Player in Android
This article explains the stepwise process as to how to build a Video Player using Android Studio. For viewing videos in android, there is a special class called "MediaPlayer". In this article, we will be having 2 videos which are connected by the "Dialog box", i.e a dialog box will come after compl
3 min read
How to Upload a Video in Firebase Database using Android Studio?
Firebase is a mobile and web application development platform. It provides services that a web application or mobile application might require. Firebase provides secure file uploads and downloads for the Firebase application. This article explains how to build an Android application with the ability
3 min read
Overview of Facebook Audience Network
In order to earn money from the Android or iOS app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android or iOS app is by integrating a third party advertisement e.g known as Facebook Audi
4 min read
How to Add Share Button in Toolbar in Android?
In this article, we are going to create a simple Share Button in the Toolbar in Android. The Share Button is used to share information on mail, Bluetooth, Facebook, Twitter, WhatsApp, etc to an individual person or a group on any social media. We can share any type of message like text, images, vide
4 min read
Implementation of Facebook’s Android Device Year Class Library in Android
As developers, we always aim to create an application that would run smoothly on millions of devices, however, the performance of practically every application is influenced by the device specifications. There are currently over 16,000 handsets on the market with varying specifications, and the appl
3 min read
How to Create Gradient Animations Like Instagram using Spark Library in Android?
In this article, we are going to implement Spark Library. Here we going to show an animation that will change the colors of the activity linearly. This feature can be simply used to show an animation and when a user loads an activity Or can also be used to show animation on the Splash Screen. Let's
2 min read
How to Add YouTube Live Stream Feature in Android?
YouTube provides a service to make a live stream video on their platform to connect with your subscribers. In this article, we will take a look at the implementation of YouTube video live streaming video in Android App. What we are going to build in this article? We will be building a simple applica
4 min read