![]() |
VOOZH | about |
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.
There are mainly five types of flexible, high-performing format available in Facebook Audience Network
In this article let's integrate Facebook Audience Network Interstitial ads in the Android app.
Interstitial Ad: Interstitial ad is a full-screen ad that covers the whole UI of the app. The eCPM (Effective Cost Per Mille) of Interstitial ads are relatively higher than banner ads and also leads to higher CTR(Click Through Rate) which results in more earning from the app.
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.
implementation 'com.facebook.android:audience-network-sdk:5.+'
<uses-permission android:name="android.permission.INTERNET"/>
In the activity_main.xml file add only one Button, so whenever the user clicks the Button the Rewarded video ad will be played.
// Creating an object of Button class
Button showInterstitialBtn;
// link those objects with their respective id's that we have given in activity_main.xml file
showInterstitialBtn=(Button)findViewById(R.id.showInterBtn);
// initializing the Audience Network SDK
AudienceNetworkAds.initialize(this);
// creating object of InterstitialAd
InterstitialAd fbInterstitialAd;
private void showInterstitial()
{
// initializing InterstitialAd Object
// InterstitialAd Constructor Takes 2 Arguments
// 1)Context
// 2)Placement Id
fbInterstitialAd = new InterstitialAd(this, "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID");
// loading Ad
fbInterstitialAd.loadAd();
}
Note: Replace "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID" with your own placement id to show real ads.
void showInterstitial()
{
// Checking If Ad is Loaded or Not
if(fbInterstitialAd.isAdLoaded())
{
// showing Ad
fbInterstitialAd.show();
}
else
{
// Loading Ad If Ad is Not Loaded
fbInterstitialAd.loadAd();
}
}
// click listener to show Interstitial Ad
showInterstitialBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showInterstitial();
}
});
// Interstitial AdListener
fbInterstitialAd.setAdListener(new InterstitialAdListener() {
@Override
public void onInterstitialDisplayed(Ad ad) {
// Showing Toast Message
Toast.makeText(MainActivity.this, "onInterstitialDisplayed", Toast.LENGTH_SHORT).show();
}
@Override
public void onInterstitialDismissed(Ad ad) {
// Showing Toast Message
Toast.makeText(MainActivity.this, "onInterstitialDismissed", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Ad ad, AdError adError) {
// 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();
}
});