Integrating the Android SDK

Downloading the SDK

To download the Marketplace Android SDK, follow these steps:

  1. Go to Revenue Desk and sign-in
  2. On the left menu bar select SDKs

7167c64-Screen_Shot_2020-08-05_at_13.06.07__1_.png

  1. Under Android, click Download.

Note

The Fyber Marketplace SDK Zip folder contains a test app that publishers can use for reference on how to integrate the SDK, how ads from Marketplace appear or to troubleshoot issues.

Starting the Process

Integrating the Android SDK begins when 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)

To understand more about Fyber modules, click here

Step 1: Integrating the SDK

Fyber supports both Gradle dependencies or manual download to integrate our SDK:

Gradle

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.

Groovy

allprojects {
  repositories {
    // add this
    maven {
        url  "https://fyber.bintray.com/marketplace" 
    }
  }
  // ...
}
  1. Save your file
  2. Add the following to your app’s app level build.gradle file inside the dependencies section:

Groovy

// define the fyber marketplace version as a variable for easier upgrades
def fyberMarketplaceVersion = '7.7.0'

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 first.
  2. Copy the ia-sdk-lib-release-x.y.z.aar from the InneractiveAdSDK folder into your project libs folder.
  3. Add the following to your project's build.gradle file:

Add Script

repositories { 
    // ...
 
    // add a flat dir repository
    flatDir {
        dirs 'libs'
    }
}

def fyberMarketplaceVersion = "7.7.0"

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 you use the Google Play Services, as otherwise we aren't able 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:x.y.z')
    implementation ('com.google.android.gms:play-services-ads-identifier:x.y.z') // or implementation ('com.google.android.gms:play-services-ads:x.y.z')
}

If you have not integrated Google Play Services yet, please follow the Google Play Services integration guide.

Step 3: Updating Your Android Manifest File

  1. The following mandatory permissions are automatically merged 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 more demand for such mediums as Rich Media (MRAID2.0 support) and location-based ads:

Adding for More Demand

<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"/>
  1. Finally, add the Google Play Services version number as meta-data:

Adding the Google Play Services Number

meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Note

If the targetSDKVersion is lower than 14, you must enable hardware acceleration in order for the video to perform optimally. Add android:hardwareAccelerated="true" in the manifest or within the activity which integrates your ads.

Want to view a full Android Manifest example?

Step 4: Initializing the SDK

Once you've added all your Android Manifest information and are ready to start calling ads, you must initialize the Inneractive Ads SDK before requesting those ads to load. To do this:

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

Pass Your Activity

public class MainActivity extends Activity {
 
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      InneractiveAdManager.initialize(this, ""); 
   }
 
   @Override
   protected void onDestroy() {
      if (isFinishing()) {
          InneractiveAdManager.destroy();
      }
   } 
}

When you're finished using the library and don't intend to display more ads, call InneractiveAdManager.destroy() to close it out. If you intend to destroy the library from within your activity's onDestroy method, check to ensure that the activity has really finished.

Initialization Callback

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

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

Java

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, please check your dependencies and add the “video-kit”, “mraid-kit” to it. More details here
  • 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. Please see here

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);

//Optionaly, 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 integration of the Android SDK! Now it's time to integrate other ad types:

Note

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

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

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:

Java

/**
     * 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:

Java

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. Using the boolean option is inferior and is to be deprecated during 2020.

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.

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

/*** Set the us privacy setting string     
* @param consentString a non empty String     
*/
public static void setUSPrivacyConsent(String consentString) {…}


// Calling the consent method  		     
InneractiveAdManager.setUSPrivacyConsent("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.clearUSPrivacyConsent();
 

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)

Java

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.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request