Facebook Native Banner Ads Integration in Android App | Admob Alternative Ad network
SEOExpart
May 18, 2020
2 Comments
Hi, Today I am going to show you How to integrate Facebook Native Banner Ads in Android App. In the last post, I have shown you how to integrate Facebook Banner Ads in Android App. Let's start.
First, add the below dependency in build.gradle(Module: App) for importing Facebook ads SDK.
Then you have to create a new layout for your Native Banner Ad, named it native_banner_ad_layout.xml
Then paste the below code in native_banner_ad_layout.xml file.
Now move to the MainActivity.java file, first import the Facebook ads SDK write the following code.
That's it. Thank you.
First, add the below dependency in build.gradle(Module: App) for importing Facebook ads SDK.
Code:
And then move to the activity_main.xml file, then paste the below layout code.
Code:
It will show your ad bottom of the screen if you want to show your ad Top of the screen you need to write android:layout_alignParentBottom="true". Then you have to create a new layout for your Native Banner Ad, named it native_banner_ad_layout.xml
Code:
So the final full code will be in activity_main.xml file is as follows:
Code:
Now move to the MainActivity.java file, first import the Facebook ads SDK write the following code.
Code:
Then paste the below code above Oncreate.
Code:
Now initialize the Facebook SDK in Oncreate.
Code:
Then create NativeBannerAd object, set an AdListener, then retrieve the "Native Banner Ad's" properties and display it in onAdLoaded() method. It will display the ad once it is loaded successfully. After that call loadAd() after AdListener in your Activity as follows.
Code:
Then paste the following code in your activity after Oncreate.
Code:
So the final code will be in your java activity file is as follows:
Code:
Now if you run your App you will see the Native Banner ad.That's it. Thank you.