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
ReplyDeleteI 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...
ReplyDeleteNotwithstanding, being a long way from ordinary promoting as perhaps, likewise, it has confounded numerous producers that are uncertain how to use the framework to drive income and new openness.mytoolstown
ReplyDeleteبهینه سازی موتورهای جستجو به زبان عربی می تواند نقش بسیار مهمی در موفقیت بازاریابی و تجارت در کشورهای عربی داشته باشد. با توجه به اینکه زبان عربی یکی از پرکاربردترین زبان های دنیاست، بهینه سازی محتوای وب سایت ها به این زبان می تواند دسترسی به بازارهای بزرگ و متنوع عربی را تسهیل کند. استفاده از سئو زبان عربی و کلمات کلیدی مناسب و محتوای بومی سازی شده به زبان عربی می تواند باعث افزایش بازدید وب سایت و جذب مشتریان جدید شود.
ReplyDeleteخدمات حمل و نقل تریدست شامل حمل و نقل هوایی، زمینی، ریلی و دریایی میشود. این تنوع در خدمات، امکان انتخاب بهترین و مناسبترین روش حمل و نقل را برای مشتریان فراهم میکند. تریدست با داشتن شبکه گستردهای از شرکای تجاری در سراسر جهان، توانسته است خدمات ترانزیت بینالمللی را با سرعت و دقت بالا انجام دهد.
ReplyDelete