Integrating the Android SDK

Before Starting

Integrating the Android SDK begins once you decide which of the modules you want to integrate.

You can choose from the following:

  • ia-sdk-core (Required for all)
  • ia-mraid-kit (HTML/MRAID content)
  • ia-video-kit (Rendering/Video content)

Note

We recommend including all the libraries and configuring the content at the placement level.

Unity Wrapper

In addition to the native Android and iOS SDKs, the Marketplace SDK supplies a unity wrapping package, which can be used to import the Marketplace SDKs into a Unity project.

The Marketplace Unity wrapper package is built upon the Google Unity jar Resolver. It works by adding the native Android/iOS dependencies to the exported native projects made at Unity run time.

To use the Unity Wrapper, download the relevant unitypackage file and import it into your project.

Note

  • For the Maven Central URL, click here
  • Currently, the Marketplace Unity package does not provide any Unity bridging for requesting ads using Unity APIs.

Step 1: Integrating the SDK in your App

Fyber supports both Maven Central dependencies or manual download to integrate our SDK. 
Select which option you want to use to integrate the SDK:

Maven Central    

Add Fyber's maven repository and dependencies to your gradle build script:

  1. Add the following to your app’s project level build.gradle file inside the repositories section:

In project level build.gradle there are usually two repositories sections - one for buildscript and one for allprojects. Add the entry in allprojects.

allprojects {
  repositories {
    // add this
    mavenCentral()
  }
  // ...
}
  1. Save your file
  2. Add the following to your app’s app level build.gradle file inside the dependencies section:
// Define the Fyber Marketplace version as a variable for easier upgrades
def fyberMarketplaceVersion = '7.8.3'

dependencies {
    // ...

    // add the relevant fyber marketplace libraries
    implementation "com.fyber.vamp:core-sdk:${fyberMarketplaceVersion}"
    implementation "com.fyber.vamp:video-kit:${fyberMarketplaceVersion}"
    implementation "com.fyber.vamp:mraid-kit:${fyberMarketplaceVersion}"
  
    // ...
}
  1. Save the file.
Manual Download    
  1. Download the Fyber Marketplace SDK.
    If you do not have an account, create one here.
  2. Copy the following files from the InneractiveAdSDK folder into your project libs folder.

    ia-mraid-kit-release-7.8.3.aar
    ia-sdk-core-release-7.8.3.aar
    ia-video-kit-release-7.8.3.aar
  3. Add the following to your project's build.gradle file:
repositories { 
    // ...
 
    // Add a flat dir repository
    flatDir {
        dirs 'libs'
    }
}

def fyberMarketplaceVersion = "7.8.3"

dependencies {
  // Add the fyber marketplace AAR libraries
  implementation (name:"ia-sdk-core-release-${fyberMarketplaceVersion}", ext:'aar')
  implementation (name:"ia-video-kit-release-${fyberMarketplaceVersion}", ext:'aar')
  implementation (name:"ia-mraid-kit-release-${fyberMarketplaceVersion}", ext:'aar')
}

Step 2: Integrating Google Play Services

We recommend using the Google Play Services, otherwise we are unable to access your Google Advertising ID. This leads to limited ad inventory, as an increasing number of advertising campaigns require the identifier. This ID is also essential for tracking daily active users (DAU) on your app.

  1. Add the following to your build.gradle dependencies section for Google Play Services:

Adding Dependencies

dependencies {
    implementation ('com.google.android.gms:play-services-base:Version#')
    //Use only the ads identifier library
//Implementation ('com.google.android.gms:play-services-ads-identifier:x.y.z') // or implementation ('com.google.android.gms:play-services-ads:x.y.z') }

For more information about Google Play Services yet, click here.

Step 3: Updating Your Android Manifest File

  1. Add the following mandatory permissions into your application's AndroidManifest.xml:

Adding Mandatory Permissions

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Note

ACCESS_NETWORK_STATE permission is used to differentiate Wifi from a cellular network.

  1. Add the following permissions to enable your app to get richer and broader demand

Recommended permissions for better targeting

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Step 4: Initializing the SDK

Once you have added all your Android Manifest information and are ready to start requesting ads, you must initialize the Inneractive Ads SDK :

  1. Call InneractiveAdManager.initialize(context, <"appID">), and pass on your Activity or application context:

Pass Your Activity Context 

public class MainActivity extends Activity {
 
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      InneractiveAdManager.initialize(this, "Enter_Your_Fyber_AppID"); 
   }
 
   @Override
   protected void onDestroy() {
      if (isFinishing()) {
           //Optionally destroy the SDK after the activity has been destroyed
InneractiveAdManager.destroy(); } } }

Optionally, when you're finished using the library and do not intend to display more ads, call InneractiveAdManager.destroy() to release any resources being used by the SDK.

Note

If you intend to destroy the library from within your activity's onDestroy method, check to ensure that the activity has really finished.

Locating the App ID

  1. Search for and select your app in the Console

     

  2. Click the three horizontal dots at the end of the row
  3. Click Integration Options:

The Info window opens and your App ID and SDK information is displayed:

Initialization Callback

Starting from Marketplace SDK version 7.5.4, it is possible to add an initialization callback which notifies you about the initialization status of the SDK.

The callback can be optionally passed to the InneractiveAdManager in the following manner:

InneractiveAdManager.initialize(context, appId, new OnFyberMarketplaceInitializedListener() {
           @Override
           public void onFyberMarketplaceInitialized(FyberInitStatus status) {
               // ...
           }
});

Where the Status being returned in the initialized callback is:

  • SUCCESSFULLY - when the SDK has been successfully initialized.
  • FAILED_NO_KITS_DETECTED - when only the “core” Fyber Marketplace library has been detected. When this is the status, check your dependencies and add the “video-kit”, “mraid-kit” to it. 
  • FAILED - When the SDK has failed to communicate with our servers and could not be initialized at this time.
  • INVALID_APP_ID -the appId being passed to the initialize is incorrect. Please check your configuration or contact us for assistance. 

Important: Regarding the "Failed" Status

Fyber currently recommends using the SDK and performing ad requests when the FyberInitStatus is “FAILED”, as the SDK, internally, attempts to re-initialize itself when an AdRequest is executed. The above callback is not invoked in such cases.

Passing a User ID to the SDK (from v.7.7.0)

The following code snippet demonstrates how to set a User ID for this SDK session.

Note

The initial method of the SDK must be called in advance and there is no need to wait for the onFyberMarketplaceInitialized callback

String userId = ...;
//Without reflection, using an import of the InneractiveAdManager class -
InneractiveAdManager.setUserId(userId);

//Optionally, using reflection as an example -
Class FyberInneractiveAdManagerClass = 
Class.forName("com.fyber.inneractive.sdk.external.InneractiveAdManager"); Method setUserIdStaticMethod =
FyberInneractiveAdManagerClass.getDeclaredMethod("setUserId", String.class); setUserIdStaticMethod.invoke(null, userId);

You have completed the basic integration of the Android SDK! Now it's time to integrate other ad types.  For details of Android Ad Formats, click here.

Note

Review the below GDPR related instructions (available starting Android v7.1.5 SDK and legacy version v6.5.6)

Locating your Spot ID

Follow the instructions below to find your Spot ID and make sure you enter the correct credentials.

  1. Go to the Inventory window
  2. Select the app for which you want to locate the ID

The Spot ID is located in brackets, next to the spot name. 

  1. Click the number to save the ID to the clipboard.

Step 5: Adding User Consent

GDPR

The General Data Protection Regulation of the European Union requires you to scope your user's consent. A user could be within the GDPR scope for your app when one or all of the following apply:

  • The user is currently located in the EU
  • The user has registered with the app as an EU resident
  • The app is specifically targeted to EU users

Note

When you set a GDPR consent value for a user, Fyber concludes that you have decided that the user is subject to GDPR rules, even if the user is outside Europe. If, based on your legal position, your non-EU users are not subject to GDPR, do not pass any consent value for them.

We recommend that you consult with a legal advisor to determine the best approach for your business. It is also highly recommended to collect user consent with a certified Consent Management Platform (CMP).

For a full list of CMPs, click here.

Once you have collected the user’s consent, you can pass it onto the SDK using the following API:

/**
     * Set the general data protection regulation user consent status
     * @param wasConsentGiven
     */
    public static void setGdprConsent(boolean wasConsentGiven) {…}
    
    // Calling the consent method
    
    InneractiveAdManager.setGdprConsent(true);

    /**
    * Set the general data protection regulation consent string
    * @param gdprConsent the consent string
    */
    public static void setGdprConsentString(String gdprConsent) {…}

    // Calling the consent method

    InneractiveAdManager.setGdprConsentString("consentString");

GdprConsent is a boolean. It is true if you have the user’s consent. If you do not have the user's consent, it is false.
GdprConsentString is a string.

If you don’t pass the user’s consent to the SDK, only contextual ads are shown to that user.

To clear the consent flag and consent data, the following API, use the following API:

InneractiveAdManager.clearGdprConsentData();

It is highly recommended to use the 2nd option of passing a consent string per the IAB's Transparent & Consent Framework by using a valid CMP (Consent Management Platform). This is the most common form of consent communication worldwide and is crucial in order to enjoy ad monetization in the EU. 

We recommend that the first time you gather the user’s consent, you pass it onto the SDK after starting the SDK but before requesting an ad. The SDK then takes the user’s consent into consideration when initializing. In the following sessions, you need only call the API if the user updates their consent.

Note

When Fyber Marketplace is being mediated by MoPub, we recommend to set the GDPR flag directly on MoPub’s consent collection manager.

This manager forwards the consent state to the Fyber Marketplace and there is no additional requirement to explicitly set the GDPR flag on the Fyber Marketplace directly.

More information on GDPR can be found under the GDPR Resource Page and FAQs.

CCPA

The intention of the California Consumer Privacy Act of 2018 (CCPA) is to protect the personal information of California residents. CCPA applies to all companies doing business in California. If a California resident uses an app developer’s mobile app, CCPA applies to the developer and every company that processes the personal information of the app’s users.
CCPA came into effect on 1 January 2020.

For more information on Fyber and CCPA, refer to Fyber’s Resource Page.
For more information about CCPA, refer to the IAB CCPA Compliance Framework.

If you choose to allow users to 'opt-out of the sale of their personal information' then you may use the following:

Once you have obtained a user response to an opt-out option, you can pass it to the SDK using the following API:

CCPA API

/*** Setting the US privacy setting string     
* @param consentString a non empty String     
*/
public static void setUSPrivacyString(String consentString) {…}

// Calling the consent method  		     
InneractiveAdManager.setUSPrivacyString("1YNN"); // This is an example value when the user chose NOT to 'opt-out'

To determine what value to use for the US Privacy String, refer to the IAB document here.
Example values:

  • When CCPA does not apply (for example if the user is not a resident of California) you can either skip this API or use the following value 1---
  • If the user choses NOT to opt out, and is ok with advertising as usual, you can use 1YNN
  • If the user chooses to restrict advertising and opt out, you can use 1YYN

To clear the privacy setting flag and opt-out data use the following API:

CCPA Clear Privacy Settings

InneractiveAdManager.clearUSPrivacyString();

Step 6: app-ads.txt

The simple app-ads.txt standard helps prevent the unauthorized selling of in-app inventory and app domain spoofing.

For details of listing your Developer Website URL in the Google Play Store, click here.

Step 7: Optional - Using the Fyber Marketplace SDK in Secure Only Mode (since version 7.2.1)

InneractiveAdManager.useSecureConnections(boolean useSecureConnnections)

This API described above allows you to control how should the SDK perform any and all network connections.

By invoking this setter with a value of true all outgoing network connections from the Fyber Marketplace SDK will be using ssl/https. The default behaviour is not to use secure connections.

Secure Demand Notice

By requesting secure only content, you potentially decrease the amount of demand which can be rendered by the SDK.

Note

The Android application level secure API (network-security-config cleartextTrafficPermitted) takes precedence over this value - i.e. if you set cleartextTrafficPermitted to false and invoke the useSecureConnections setter with a value of false, the SDK behaves as if you requested secure only connections.

Back to Top ⇧