Implement Interstitial Ads in Android with Facebook Audience Network
Implement Interstitial Ads in Android with Facebook Audience Network
(Updated with Android SDK 6.2.0)
Changes are:
- Change of InterstitialAdListener
- load ad with interstitial AdListener
In this post, we implement Facebook Interstitial Ads using the Facebook Audience Network. We will show test ads by Facebook Audience Network on our Android device.
Then Create an app under MyApp section on top-right corner.
![]() |
Create an App |
Then name your app and click create an app.
![]() |
Name your App |
Then Click on Audience Network from the product section.
![]() |
Click on Audience Network |
Then click on Get started of monetization and then select a business account.
![]() |
Monetization and business account. |
Then name your first app.
![]() |
Name your app |
Then click on Android from platforms.
![]() |
Click on Android from platform section |
If your app is live then write your app link, else click on the app is not live.
![]() |
The app is not Live |
Then under creating placement, add a Placement name.
![]() |
Name your Placement |
Then Click on Interstitial Ad from Placements.
![]() |
Click on Interstitial |
Then click on Create placement. and Then copy your placement Id from next Page.
![]() |
Copy your Placement Id |
*Your Placement ad is only working on your app if you added a payment account with your account.*
So, Add a Test Device in the Testing section to show test ads in your Android app without payment account.
Then, click on a Testing section in the left menu on business.facebook.com
![]() |
Click on Testing |
Under Add Test Device, Enter your test device Id.
For Test Device Id of Android Mobile.
Open Settings -> click on google -> click on Ads -> your AAID is write in bottom of your screen.
Then enter your device id and click on add device.
Then select the ad type of your added device.
![]() |
Add Test Device |
Then select Interstitial from ads.
![]() |
Select Ad Type |
Now your ad is set up properly. Now open Android Studio and create a new project.
After the Gradle sync Then opens your app-level Gradle file and add Facebook ads dependency.
implementation 'com.facebook.android:audience-network-sdk:6.2.0'
Then Paste your placement Id in your project String.xml file
String.xml
<string name="Facebook_Interstitial_placement">1449151565259453_1452519068256036</string>
Then we create a button to show Interstitial Ad on button click.
acivitymain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interstitial"
android:id="@+id/button"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Then we create a variable for Button and Interstitial Ad and find Ids in our java file.
MainActivity.java
private InterstitialAd interstitialAd;
Button btn;
String TAG = "Tag";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.button);
Then create a click listener for button and then initialize your Interstitial Ad in Button Click listener.
MainActivity.java
package studio.harpreet.myfbtestads;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.facebook.ads.Ad;
import com.facebook.ads.AdError;
import com.facebook.ads.AdSize;
import com.facebook.ads.AdView;
import com.facebook.ads.AudienceNetworkAds;
import com.facebook.ads.InterstitialAd;
import com.facebook.ads.InterstitialAdListener;
public class MainActivity extends AppCompatActivity {
private InterstitialAd interstitialAd;
Button btn;
String TAG = "Tag";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.button);
AudienceNetworkAds.initialize(this);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
interstitialAd = new InterstitialAd(MainActivity.this, getResources().getString(R.string.Facebook_Interstitial_placement));
InterstitialAdListener interstitialAdListener = new InterstitialAdListener() {
@Override
public void onInterstitialDisplayed(Ad ad) {
// Interstitial ad displayed callback
Log.e(TAG, "Interstitial ad displayed.");
}
@Override
public void onInterstitialDismissed(Ad ad) {
// Interstitial dismissed callback
Log.e(TAG, "Interstitial ad dismissed.");
}
@Override
public void onError(Ad ad, AdError adError) {
// Ad error callback
Log.e(TAG, "Interstitial ad failed to load: " + adError.getErrorMessage());
}
@Override
public void onAdLoaded(Ad ad) {
// Interstitial ad is loaded and ready to be displayed
Log.d(TAG, "Interstitial ad is loaded and ready to be displayed!");
// Show the ad
interstitialAd.show();
}
@Override
public void onAdClicked(Ad ad) {
// Ad clicked callback
Log.d(TAG, "Interstitial ad clicked!");
}
@Override
public void onLoggingImpression(Ad ad) {
// Ad impression logged callback
Log.d(TAG, "Interstitial ad impression logged!");
}
});
// For auto play video ads, it's recommended to load the ad
// at least 30 seconds before it is shown
interstitialAd.loadAd(interstitialAd.buildLoadAdConfig().withAdListener(interstitialAdListener).build());
}
});
}
}
Now our Interstitial Ad is successfully loaded on button click.
Subscribe to Harpreet studio on Youtube
Like Harpreet Studio on Facebook
Follow me on Instagram
But 4.1 risk violation our apps please help me brother.
ReplyDeleteThis is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post free local classifieds
ReplyDeletethanks for the tips and information..i really appreciate it.. facebook ads
ReplyDeleteIn the "Freebies" section on DigitalPoint you will find many threads with the title "free proxy promotion" or something very similar. find out here now
ReplyDeleteThey have been viewed as the most loathed type of web promoting accessible. With pop-ups being so irritating notwithstanding, purchasers might ask why they are as yet being utilized so oftentimes. Truly pop-ups are appallingly disturbing, yet they are for sure viable generally speaking. mélybölcsÅ‘s szállÃtás Europa-Road Kft
ReplyDeleteThe blog writings were so nice, I wished they neever ended.
ReplyDeletebuy facebook contest votes
This cool application allows you easily to feature them across the board all around made collection. buy cheap instant instagram views
ReplyDeleteYour blog is too much amazing. I have found with ease what I was looking. Moreover, the content quality is awesome. Thanks for the nudge! https://fbox.today
ReplyDeleteI am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. https://freeinlinemovies.site
ReplyDeletenice bLog! its interesting. thank you for sharing.... https://freetv.today
ReplyDeleteThank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. https://4movierulz.space
ReplyDeletePretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. https://openload.store
ReplyDeleteI visit your blog regularly and recommend it to all of those who wanted to enhance their knowledge with ease. The style of writing is excellent and also the content is top-notch. Thanks for that shrewdness you provide the readers! https://pagalmovies.life
ReplyDeleteThis particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… https://poppygreens.site
ReplyDeletei never know the use of adobe shadow until i saw this post. thank you for this! this is very helpful. https://hdtoday.website
ReplyDeleteI know this is one of the most meaningful information for me. And I'm animated reading your article. But should remark on some general things, the website style is perfect; the articles are great. Thanks for the ton of tangible and attainable help. https://playdesi.site
ReplyDeletethnks for sharing us https://123moviesfree.media
ReplyDeletethnks for shairng us https://filmyhit.today
ReplyDeletethnks for sharing us https://ipagalmovies.site
ReplyDeleteThis is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. https://lookmovies.stream
ReplyDeletethnks for sharing us https://freetvshows.live
ReplyDeleteThanks for sharing us. https://soap2day.systems
ReplyDeleteI have read your article couple of times because your views are on my own for the most part. It is great content for every reader. https://soap2day.black
ReplyDeleteIts a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
ReplyDeletehttps://watchserieshd.media
Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work.
ReplyDeletehttps://watchserieshd.space
Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family.
ReplyDeletehttps://watchserieshd.site
It is a great website.. The Design looks very good.. Keep working like that!.
ReplyDeletehttps://watchserieshd.space
I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work...
ReplyDeleteThanks for picking out the time to discuss this, I feel great about it and love studying more on this topic. It is extremely helpful for me. Thanks for such a valuable help again. https://1flixtor.com
ReplyDeleteThis is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work https://lookmovies.video
ReplyDeleteI got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work. https://1movies.media
ReplyDeleteWell-Written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing – can't pause to read more posts. Thanks for the precious help. https://soap2day.black
ReplyDeleteHaving a smart phone has become more a status symbol for people than a requirement. In such times, it's a must you launch yourself with some cool gadgets and apps to get the full advantage of situation. Android apps development is such a sector which can provide you with these benefits if you stick to an effective way. subway surfers mod
ReplyDeleteAndroid apps have revolutionized the way businesses connect or reach out to their target audience. This article gives amazing reasons why your business needs an Android app. subway surfers mod menu
ReplyDelete