FeedAd Android SDK

This guide explains how to integrate the FeedAd SDK into an Android app.

Requirements

  • Android API from Android 4.3. upwards (API 18+)
  • Gradle 4.1+
  • Gradle Android Plugin 3+
  • A FeedAd client token to be found in the admin panel

Installation

The SDK dependency can be included via the following entry inside the app's build.gradle:

repositories {
    mavenCentral()
}

dependencies {
    implementation('com.feedad.android:feedad-sdk:1.5.8') {
        transitive = true
    }
}

You also have to include the AndroidX support library if your app does not already depend on it. If you depend on a newer version than 1.1.0, you do not have to downgrade your dependency.

dependencies {
    // add this line if you don't already include it
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.annotation:annotation:1.1.0'
}

Sync your gradle files and build your project after adding the dependencies.
Your IDE should now be able to find the class com.feedad.android.FeedAd.

Initialization

The SDK needs to be initialized prior to ads being requested.
Call the FeedAd.init(...) method anywhere before your first ad request.
This can be as soon as the onCreate() method of your application, but since version 1.4 it does not need to be called as early as that. Multiple calls of the init method do not have any negative effects. All calls after the first one are simply ignored.

/**
 * This method initializes the FeedAd SDK. Call it before requesting ads.
 * @param context any Context instance. The SDK will hold a reference to the Application Context.
 */
public void initFeedAd(Context context) {
    FeedAd.init(context, "your client token");
}

Additional SDK Options

You can specify additional SDK options by using the 3rd parameter within the init(...) call. This parameter takes an options instance, that can be built using the builder provided by FeedAdSdkOptions.newBuilder().

This is what an initialization with options would look like:

public void initFeedAd(Context context) {
    FeedAd.init(context, "your client token",
            FeedAdSdkOptions.newBuilder()
                            .setEnableLogging(true)
                            .setWaitForConsent(true)
                            .setAllowLocationDataUsage(true)
                            .build()
    );
}

Here are all the options that can be set through the builder:

Option Type Default Description
setEnableLogging boolean false If the SDK should log debug information into the console.
setWaitForConsent boolean false If the SDK should wait for IAB TCF 2 consent for the FeedAd Vendor (781).
setAllowLocationDataUsage boolean false If the SDK is allowed to send geolocation data alongside ad requests.

Location data usage

The SDK does neither specify location service permissions inside its manifest, nor does it request permission, if it is not given at request time. All implementation regarding location service permissions have to be written by you within your app code. If the flag is set to true, but the user has not given permission before the ad request is sent, the request will be sent without any location data.
Please discuss with your FeedAd account manager, if enabling location data usage is sensible for your use-case.

Integration

Add a FeedAdView to your layout to quickly check if everything is working as expected:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <!-- your other views -->

    <com.feedad.android.FeedAdView
        android:id="@+id/texture_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:feedadPlacementId="your-placement-id"
        />

    <!-- your other views -->

</LinearLayout>

Placement ID?

You can choose placement IDs yourself. A placement ID should be named after the ad position inside your product. For example, if you want to display an ad inside a list of news articles, you could name it "ad-news-overview".
A placement ID may consist of lowercase a-z, 0-9, - and _. You do not have to manually create the placement IDs before using them. Just specify them within the code, and they will appear in the FeedAd admin panel after the first request. Learn more about Placement IDs and how they are grouped to play the same Creative

It's a wrap!

If you start your app, you should now be able to see ads running wherever you've included the view.
If there are no ads yet, you should enable test ads through the FeedAd admin panel.

It's time to learn more:

  1. See multiple ways to integrate FeedAds into your app
  2. Learn about configuration options and how to manage the SDK's playback
  3. Listen to the SDK's events
  4. Learn how to add interstitial Ads into your app

Demo Apps

If you rather prefer to dive right into the code, you can also take a look at our Android demo apps written in Java that demonstrate a working integration.