Rapid Subscribe Android App

Rapid Subscribe Android App
Rapid Subscriber

Recent Posts

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 on Facebook Developer console
Create an App 

Then name your app and click create an app.



Name your App on Facebook Developer Console
Name your App 

Then Click on Audience Network from the product section.



Facebook Audience Network
Click on Audience Network


Then click on Get started of monetization and then select a business account.



Monetization and Business account
Monetization and business account.

Then name your first app.



Name your app
Name your app

Then click on Android from platforms.



Click on Android from platform section
Click on Android from platform section


If your app is live then write your app link, else click on the app is not live.



Facebook Developer Console Facebook Audience Network
The app is not Live


Then under creating placement, add a Placement name.

Facebook Developer console Facebook Audience Network
Name your Placement


Then Click on Interstitial Ad from Placements.
Facebook Developer console Facebook Audience Network
Click on Interstitial


Then click on Create placement. and Then copy your placement Id from next Page.

Facebook Developer console Facebook Audience Network
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



Facebook Developer Console Facebook Audience Network
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.



Facebook Developer Console Facebook Audience Network
Add Test Device

Then select Interstitial from ads.



Facebook Developer Console Facebook audience Network
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.


 
Follow us for more posts like this, 
Subscribe to Harpreet studio on Youtube  
Like Harpreet Studio on Facebook  
Follow me on Instagram 

34 comments:

  1. But 4.1 risk violation our apps please help me brother.

    ReplyDelete
  2. This 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

    ReplyDelete
  3. thanks for the tips and information..i really appreciate it.. facebook ads

    ReplyDelete
  4. In the "Freebies" section on DigitalPoint you will find many threads with the title "free proxy promotion" or something very similar. find out here now

    ReplyDelete
  5. They 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

    ReplyDelete
  6. The blog writings were so nice, I wished they neever ended.
    buy facebook contest votes

    ReplyDelete
  7. This cool application allows you easily to feature them across the board all around made collection. buy cheap instant instagram views

    ReplyDelete
  8. Your 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

    ReplyDelete
  9. I 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

    ReplyDelete
  10. nice bLog! its interesting. thank you for sharing.... https://freetv.today

    ReplyDelete
  11. Thank 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

    ReplyDelete
  12. Pretty 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

    ReplyDelete
  13. I 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

    ReplyDelete
  14. This 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

    ReplyDelete
  15. i never know the use of adobe shadow until i saw this post. thank you for this! this is very helpful. https://hdtoday.website

    ReplyDelete
  16. I 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

    ReplyDelete
  17. This 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

    ReplyDelete
  18. I 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

    ReplyDelete
  19. Its 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.
    https://watchserieshd.media

    ReplyDelete
  20. 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.
    https://watchserieshd.space

    ReplyDelete
  21. 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.
    https://watchserieshd.site

    ReplyDelete
  22. It is a great website.. The Design looks very good.. Keep working like that!.
    https://watchserieshd.space

    ReplyDelete
  23. 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...

    ReplyDelete
  24. Thanks 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

    ReplyDelete
  25. This 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

    ReplyDelete
  26. I 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

    ReplyDelete
  27. Well-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

    ReplyDelete
  28. Having 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

    ReplyDelete
  29. Android 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