Copyright 2011 Urban Airship, Inc. All Rights Reserved.
This guide will help you get up to speed on integrating the new Urban Airship client library in your Android app. We’ll start by going over the changes from previous library versions. From there, we’ll cover the basic steps needed to integrate the library, including setting application credentials and enabling Analytics reporting to get the most out of your app deployment.
While this guide provides a high level walkthrough of the library, we also provide Javadoc documentation for the API.
You can download our latest Android client library distribution here. This zip file contains the library JAR file, as well as Eclipse sample projects with the JAR file already included.
Changes necessary to upgrade from 0.9.1:
Changes necessary to upgrade from 0.9.0:
Changes from previous older of Urban Airship Embedded Push:
If you are using Eclipse to develop your project, simply right-click on the top-level project in the Package Explorer pane and choose Properties. Click Java Build Path, Libraries, then Add External Jars. Browse to the urbanairship-lib-<version>.jar file, select it, and then click “OK”.
Otherwise, if you’re using a different IDE, just add a reference to the urbanairship-lib-<version>.jar file in your classpath, and ensure that it is bundled in your final application.
Initializing the UrbanAirship library is easy, and only requires two additional lines of code. We’ll be adding a call to UAirship.takeOff in the app’s onCreate methods. Here is a simple example:
import android.app.Application;
import com.urbanairship.UAirship;
public class MyApplication extends Application {
@Override
public void onCreate() {
UAirship.takeOff(this);
}
}
Once you’ve added the takeOff call to your application class, you’ll still need to specify your app’s credentials before it can interact with an application you’ve created on the Urban Airship dashboard (https://go.urbanairship.com). The Android client library looks for these in a file called airshipconfig.properties, in the assets subfolder of your Android project directory. There you can set your app’s key and secret, and whether the app is currently in development or production. A well-formed airshipconfig.properties file should look something like the example shown below, replacing strings such as “Your Development App Key” with the appropriate keys for your app, and setting the inProduction boolean accordingly:
developmentAppKey = Your Development App Key
developmentAppSecret = Your Development App Secret
productionAppKey = Your Production App Key
productionAppSecret = Your Production App Secret
inProduction = false
The Android library provides built-in usage reporting for your application. It will enable you to track time in app (per activity) and the results of push notifications. The only thing you need to do is instrument your activities so that the library can track start and stop events.
To determine time-in-app, the library needs to know when each activity is started and stopped. The library ships with instrumented Activity and ListActivity classes called InstrumentedActivity and InstrumentedListActivity. The simplest way to track start and stop events is to extend these classes for each of your activities.
If you would like to manually instrument your class, simply update your Activity’s onStart and onStop methods with the following:
@Override
public void onStart() {
super.onStart();
UAirship.shared().getAnalytics().activityStarted(this);
}
@Override
public void onStop() {
super.onStop();
UAirship.shared().getAnalytics().activityStopped(this);
}
If you do not wish to include analytics and reporting in your application, simply add the following line to your airshipconfig.properties file:
analyticsEnabled = false
For questions related to this release, bugs, or other concerns, don’t hesitate to email us at support@urbanairship.com, or visit our support site.