Integrate Flurry SDK for Android

Integrating with the Flurry SDK is easy and straightforward for Android developers.

Follow these instructions and in no time at all, you’ll be ready to start logging events and publishing your ads.

Prerequisites: Android API level 10 and higher.

Create an App & Get Your API Key

Start by creating an app. Once you create the app, you’ll receive a Flurry API Key, which you’ll need when using the SDK.

Important

You need to have the administrator role on your company’s account to be able to create a new app within the company.

Sign up  or  Create an App for Android

Note

For each distinct app that you create, you’ll need to acquire a unique Flurry API Key.

Install Flurry Android SDK

We recommend installing the Flurry SDK via jcenter. Instructions for this, as well as manually downloading and adding the .jar files are as follows.

Install via jcenter

The Flurry SDK is available via jcenter. You can add it to your application by including the following in your build.gradle file:

// In your main app's Gradle config file:

repositories {
  jcenter()
}

dependencies {
  // Required for Flurry Analytics integration
  compile 'com.flurry.android:analytics:7.0.0@aar'
  // Optional - If you want to use the Ads SDK
  compile 'com.flurry.android:ads:7.0.0@aar'
}

Alternatively, you can add the Flurry dependency in .jar format instead of .aar format from jcenter by including com.flurry.android:analytics:7.0.0 or com.flurry.android:ads:7.0.0 for Flurry Analytics and Flurry Ads respectively.

If you are looking to directly download the Flurry SDK packaged in .jar files, please email support@flurry.com and ask for the latest SDK be sent to you

Important

It is highly recommended to use the AAR format of the Flurry SDK. Using jars is now deprecated. Please update to AARs as Flurry will be removing jars in a future release.

Note

If you are adding the AAR format of the Flurry dependencies, you do not need to modify your AndroidManifest files or ProGuard configuration.

Configure the AndroidManifest and ProGuard Files

Below is an example of an AndroidManifest.xml file configured for both Flurry Analytics and Flurry Advertising.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.flurry.sample"
        android:versionCode="1"
        android:versionName="1.0" >

        <!-- Required permissions - Internet access -->
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <!-- Recommended permission - External memory pre-caching -->
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <!-- Optional permission - Location based ad targeting -->
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

        <application
            android:name=".MyApplication"
            android:allowBackup="true"
            android:icon="@mipmap/app_icon"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <!-- Required Activities if using Flurry Advertising -->
            <activity
               android:name="com.flurry.android.FlurryFullscreenTakeoverActivity"
               android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode| screenSize|smallestScreenSize">
            </activity>

        </application>
    </manifest>

Required Permission

Required to send analytics data back to the flurry servers

android.permission.INTERNET

Optional Permission (Highly Recommended)

If your application has network state permissions, transmission of analytics data can be optimized.

android.permission.ACCESS_NETWORK_STATE

Optional Permission

Flurry Analytics will use PASSIVE_PROVIDER to get the location information. Otherwise it will use the NETWORK_PROVIDER to fetch the last known location.

Without these permissions, only country level location information will be available.

You may call FlurryAgent.setLocation() to set the location manually if your app uses the GPS.

To disable detailed location reporting even when your app has permission, call FlurryAgent.setReportLocation(false) before calling FlurryAgent.onStartSession()

android.permission.ACCESS_COARSE_LOCATION or
android.permission.ACCESS_FINE_LOCATION

If your application has location android.permission.ACCESS_FINE_LOCATION permission, analytics will use PASSIVE_PROVIDER to get the location information. Otherwise it will use the NETWORK_PROVIDER to fetch the last known location.

Without these permissions, only country level location information will be available.

You may call FlurryAgent.setLocation() to set the location manually if your app uses the GPS. To disable detailed location reporting even when your app has permission, call FlurryAgent.setReportLocation(false) before calling FlurryAgent.onStartSession().

Specify a versionName attribute in the manifest to have data reported under that version name.

Application

If you are shipping an app, extend the Application class if you are not already doing so:

application
  android:name=".MyApplication">
  …

Configure Your Proguard.cfg File (Optional)

The following step is only necessary if you are using Proguard to obfuscate your code.

Add the following instructions to your proguard.cfg file:

# Required to preserve the Flurry SDK
-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod,Signature
-keepclasseswithmembers class * {
   public (android.content.Context, android.util.AttributeSet, int);
 }

 # Google Play Services library
  -keep class * extends java.util.ListResourceBundle {
   protected Object[ ][ ] getContents();
}

 -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
  public static final *** NULL;
 }

 -keepnames @com.google.android.gms.common.annotation.KeepName class *
 -keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
  }

 -keepnames class * implements android.os.Parcelable {
  public static final ** CREATOR;
 }

Initialize Flurry

Add the following calls to initialize the Flurry SDK by using the FlurryAgent.Builder to initialize the Flurry SDK with your project’s API key. If you are shipping an app, use the FlurryAgent Builder to init the SDK, passing it a reference to your Application Context and your project’s API key:

public class MyApplication extends Application {
  @Override
  public void onCreate() {
      super.onCreate();

      new FlurryAgent.Builder()
          .withLogEnabled(true)
          .build(this, FLURRY_API_KEY);
  }
}

It is safe to call the Builder more than once, provided that you use the same API key throughout the application. You may use any type of Context you wish. The following methods are now deprecated: setFlurryAgentListener(), setLogEnabled(), setLogLevel(), setContinueSessionMillis(), setCaptureUncaughtExceptions(), setPulseEnabled() and init().

Note

If you want to call logEvent() directly after calling build(), it is best to register a Flurry Agent listener with withListener() to make sure the SDK is initialized before logging. If you wish to make calls to logEvent() directly after initializing the SDK, it is best to register the listener FlurryAgentListener.onStartSession() for when the session has started. This will allow you to capture events as soon as the session is ready.

If you are writing an app and the minimum target is Ice Cream Sandwich or above (minSdkVersion is set to API level 14 or greater), session handling is completely automatic and you may skip steps 1 and 2. If you are instrumenting another type of Context, such as a Service, or your minimum target is Gingerbread, proceed with steps 1 or 2.

If your app is targeting Gingerbread or Honeycomb(API 10 -13), follow these steps:

  1. Insert a call to FlurryAgent.onStartSession(Context) in your Activity’s onStart() method passing it a reference to a Context object (such as an Activity or Service). Do not pass in the global Application context. If you are targeting Gingerbread, we recommend using the onStart method of each Activity in your application, and passing the Activity itself as the Context object. For services (or other Contexts), use the Service or the relevant Context as the Context object.

  2. Insert a call to FlurryAgent.onEndSession(Context) in your Activity’s onStop() method. Do not pass in the global Application context. If you are targeting Gingerbread, we recommend using the onStop method of each Activity in your application. For services (or other Contexts), ensure that onStop is called in each instrumented Service. Make sure to match up a call to onEndSession for each call of onStartSession, passing in the same Context object that was used to call onStartSession.

    As long as there is any Context that has called onStartSession but not onEndSession, the session will be continued. Also, if a new Context calls onStartSession within 10 seconds of the last Context calling onEndSession, then the session will be resumed, instead of a new session being created. Session length, usage frequency, events and errors will continue to be tracked as part of the same session. This ensures that as a user transitions from one Activity to another in your application that they will not have a separate session tracked for each Activity, but will have a single session that spans many activities. If you want to track Activity usage, we recommend using logEvent, described below.


Now test run your Android app and ensure that it builds without errors. If everything is working properly, a session will be recorded in Flurry and should be visible on your Real Time dashboard within 30 seconds.

Important

If you created the Flurry app within the last 5 minutes, the app may not yet be live on our servers and thus will not reflect real-time data. Re-run your app after 5 minutes to see your session recorded on the Real Time dashboard.

Congratulations! Your Android app is now ready to be used with Flurry Analytics.

Integrating Other Analytics Features

Once you’ve completed the basic SDK integration setup, you’re can move on to Custom Events, Revenue Analytics, Crash Analytics, and other Advanced Features.

Need Help?

Check out our robust collection of FAQs and a detailed Lexicon of key terminology. Didn’t find what you were looking for? Check out the other options to get support.