Facebook Audience Network

random

Android Studio Guidelines

Facebook Audience Network allows you to monetize your Android apps with Facebook ads. This guide will walk you through all the steps to integrate the SDK.

Prerequisites

Ensure that you have Android Studio installed.
Please see the FAQ for minimum OS version supported by Audience Network SDK.

Getting Started Steps

Step 1: Creating a New Project

Step 2: Including the SDK

Step 3: Integration Error Mode (optional)

Step 1: Creating a New Project

You can skip this step if you already have a project you want to integrate Audience Network into.
Start Android Studio and select "Start a new Android Studio Project"


Name your project and specify your company's domain.
The Package name will be your identifier if you decide to upload your app to the Google Play store.


Set your minimum Android SDK version. Audience Network requires API 15 or higher, but for the sake of
these samples, we will use API 21.


Add an Empty Activity to your Project


Name your initial Activity and click Finish.

Step 2: Including the SDK

The Audience Network SDK is part of the Facebook SDK. Follow these steps to download and include it in your project:
Using Gradle



Add the following compile statement to your app-level build.gradle (not project!), to use the latest Audience Network SDK:
dependencies {
  compile 'com.android.support:recyclerview-v7:25.3.1' // Required Dependency by Audience Network SDK
  compile 'com.facebook.android:audience-network-sdk:5.+'
}
If there are issues resolving the Audience Network SDK, make sure that you've synced your Gradle file and try restarting Android Studio.
Manual installation (Not Recommended)

If using Intellij IDEA or Eclipse, download and extract the Audience Network SDK for Android. Under the AudienceNetwork/bin folder, copy the AudienceNetwork.aar file and place it in the /libs folder in your project you might need to create the directory if it doesn't already exist. Then, add the following lines to your app's build.gradle:
repositories {
  flatDir {
    dirs 'libs'
  }
}

dependencies {
  compile 'com.android.support:recyclerview-v7:25.3.1'  // Required Dependency by Audience Network SDK
  ...
  compile(name: 'AudienceNetwork', ext: 'aar')
}
If using AudienceNetwork.jar for your project, under the AudienceNetwork/bin folder, rename the AudienceNetwork.aar to AudienceNetwork.zip, extract classes.jar file and rename it to AudienceNetwork.jar, place the AudienceNetwork.jar file in the /libs folder in your project you might need to create the directory if it doesn't already exist. Make sure your IDE's UI reflects this change. If you are using Intellij IDEA or Eclipse, right click on the libs/AudienceNetwork.jar file and choose 'Add as Library'.

The Audience Network SDK also requires the recyclerview support library.
Though not required, we recommend that you set up your project to work with Google Play Services as indicated here. This will enable the Audience Network SDK to fetch the Advertising ID more efficiently.

Step 3: Integration Error Mode (optional)

When integrating the Audience Network SDK, the integration error mode setting can be used to verify that your integration is working as intended. Specifically, this method allows you to control the SDK's behavior when used incorrectly .
  • INTEGRATION_ERROR_CRASH_DEBUG_MODE: App will crash if your build has Android FLAG_DEBUGGABLE, otherwise INTEGRATION_ERROR_CALLBACK_MODE will be used (recommended when testing).
  • INTEGRATION_ERROR_CALLBACK_MODE: App will call AdListener.onError(Ad, AdError) callback if an integration error is discovered.
// Example for setting the SDK to crash when in debug mode
AdSettings.setIntegrationErrorMode(INTEGRATION_ERROR_CRASH_DEBUG_MODE);

Next Steps

  • Follow our guides for integrating different Ad Formats in your app:
    • Native Ads
    • Interstitial Ads
    • Banners
  • Explore our Audience Network Android code samples on Github. Import the projects to your IDE and run it on either a device or the emulator.
  • Once you're ready to go live with your app and monetize, submit your app for review after ensuring it it complies with Audience Network policies and the Facebook community standards.
Android Studio Guidelines Reviewed by Code Labe on June 03, 2019 Rating: 5

Contact Form

Name

Email *

Message *

Powered by Blogger.