Version: Based on Facebook SDK version [6.16.0]
This Android library enables seamless integration of Facebook Audience Network ads into your application. It provides support for Banner Ads, Interstitial Ads, and Native Ads, with configurable options for controlling click and display limits.
- Banner Ads: Easily integrate banner ads within a
RelativeLayout. - Interstitial Ads: Manage interstitial ads with options for pre-loading and displaying at your preferred time.
- Native Ads: Create customizable native ads with flexible visual settings.
- Click and Display Limits: Set and control limits for clicks and impressions on both banner and interstitial ads.
In your root build.gradle file, add the JitPack repository as follows:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}Include the following dependency in your build.gradle file:
dependencies {
implementation 'com.github.SabbirMMS:EasyMetaAD:1.0'
}Add the following configuration in gradle.properties to enable Jetifier:
android.enableJetifier=trueTo initialize the Facebook Audience Network, use the FBInit_MMS class in your Activity:
FBInit_MMS initMms = new FBInit_MMS(this);
initMms.setTestDevices(new String[]{
"YOUR_TEST_DEVICE_ID",
"ANOTHER_TEST_DEVICE_ID"
// Add more test devices as needed
});You can set ad units for banner, interstitial, and native ads in bulk or individually. Replace "YOUR_PLACEMENT_ID" with the actual placement IDs from your Facebook ad account.
initMms.setAdUnits(
"IMG_16_9_APP_INSTALL#YOUR_BANNER_PLACEMENT_ID",
"IMG_16_9_APP_INSTALL#YOUR_INTERSTITIAL_PLACEMENT_ID",
"IMG_16_9_APP_INSTALL#YOUR_NATIVE_PLACEMENT_ID"
);initMms.setFbBannerUnit("IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID");
initMms.setFbInterstitialUnit("IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID");
initMms.setFbNativeUnit("IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID");Define the click and impression limits for banner and interstitial ads as follows:
initMms.setClickCountsAndLimits(
0, // bannerClickCount
2, // bannerClickLimit
0, // interstitialClickCount
2, // interstitialClickLimit
0, // interstitialShowCount
1 // interstitialShowLimit
);Alternatively, set limits for each ad type individually:
initMms.setBannerClickLimit(2);
initMms.setInterstitialClickLimit(2);
initMms.setInterstitialShowLimit(1);To display a banner ad within a RelativeLayout, use the following code:
RelativeLayout adContainer = findViewById(R.id.adContainer);
FBBanner banner = new FBBanner(this, adContainer);
banner.loadBannerAd(); // Loads the banner adSet the banner ad unit and manage click limits:
banner.setBannerUnit("IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID");
banner.setBannerClickLimit(2);
banner.destroyBannerAd(); // Destroys the banner adTo load an interstitial ad, use the following code:
FBInterstitial interstitial = new FBInterstitial(this);
interstitial.loadInterstitialAd(false, true);To show the interstitial ad:
if (!interstitial.showInterstitialAd(null)) {
Toast.makeText(this, "Not Loaded", Toast.LENGTH_SHORT).show();
}Configure the interstitial ad unit and manage click/show limits:
interstitial.setInterstitialUnit("IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID");
interstitial.setInterstitialLimits(2, 1); // Set click and show limits
interstitial.setInterstitialCounts(0, 0); // Reset click and show counts
interstitial.destroyInterstitialAd(); // Destroys the interstitial adTo load and display a native ad within a RelativeLayout:
RelativeLayout nativeAdContainer = findViewById(R.id.nativeAdContainer);
FBNative nativeAd = new FBNative(this);
nativeAd.loadNativeAd(new FBNative.MMS_NativeListener() {
@Override
public void onAdLoaded() {
nativeAd.ShowNativeAd(nativeAdContainer);
}
@Override
public void onAdFailedToLoad() {
// Handle the failure
}
});To customize the appearance of the native ad, use either hex color codes or predefined color constants:
nativeAd.CustomiseNativeAd("#2B2B2B", "#4670F0", "#FAFAFA", "#429472", "#E2E2E9"); // Using hex color strings
nativeAd.CustomiseNativeAd(Color.GRAY, Color.BLUE, Color.WHITE, Color.GREEN, Color.RED); // Using color constants
nativeAd.setNativeUnit("IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID");
nativeAd.destroyNativeAd(); // Destroys the native adsetClickCountsAndLimits(int bannerClickCount, int bannerClickLimit, int interstitialClickCount, int interstitialClickLimit, int interstitialShowCount, int interstitialShowLimit)setAdUnits(String bannerUnit, String interstitialUnit, String nativeUnit)setFbBannerUnit(String bannerUnit)setFbInterstitialUnit(String interstitialUnit)setFbNativeUnit(String nativeUnit)
loadBannerAd()setBannerUnit(String bannerUnit)setBannerClickLimit(int limit)destroyBannerAd()
loadInterstitialAd(boolean showAfterLoad, boolean keepPreLoaded)showInterstitialAd(Intent intent)setInterstitialUnit(String interstitialUnit)setInterstitialLimits(int clickLimit, int showLimit)setInterstitialCounts(int clickCount, int showCount)destroyInterstitialAd()
loadNativeAd(MMS_NativeListener listener)ShowNativeAd(RelativeLayout container)CustomiseNativeAd(int bgColor, int titleColor, int descColor, int buttonColor, int buttonTextColor)CustomiseNativeAd(String bgColor, String titleColor, String descColor, String buttonColor, String buttonTextColor)setNativeUnit(String nativeUnit)destroyNativeAd()