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 monetizing your apps.
Prerequisites: Android API level 16 and higher if using SDK version 8.0.0 or newer. Older SDK versions are API 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.
You need to have the administrator role on your company’s account to be able to create a new app within the company.
For each distinct app that you create, you’ll need to acquire a unique Flurry API Key.
Install Flurry Android SDK¶
If you are looking to manually download the Flurry SDK and add the .jar files follow the instructions for Manual SDK Integrations.
We recommend installing the Flurry SDK via jcenter, instructions 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
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.
If you are adding the AAR format of the Flurry dependencies, you do not need to modify your AndroidManifest files or ProGuard configuration.
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:
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().
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:
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.
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.
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¶
Was this document helpful?