Integrate your Pre-BlackBerry 10 app with Localytics by following these
instructions.
This integration guide is for BlackBerry OS 4.5 and above and assumes you are using
the Eclipse JDE Plugin. However the same steps will work if you are working with the
RIM JDE.
There are several reasons we prefer to offer the Pre-BlackBerry 10 client as source
only:
- The process for importing a jar into a BlackBerry project differs with every
version of Eclipse.
- Using external jar files in the BlackBerry JDE requires creating a second
project which complicates the build cycle.
- It is easy to cause the app not to launch because of a ‘verification error’ when
working with external jars.
If you have different requirements please contact support.
-
In your Localytics
Dashboard, create a new
application and copy the application key.
-
Download our Localytics
BlackBerry SDK.
-
Add the source code to an existing project by copying the Localytics’
com folder into your project’s src folder,
such that the Localytics libraries are located at
<project>\src\com\Localytics\LocalyticsSession.
-
Import the library by adding the following code to the top of your main
activity.
import com.Localytics.LocalyticsSession.*;
-
Create the object by adding the following code to your application class, or
the class that calls .enterEventDispatcher().
Maintain the
LocalyticsSession object in your Application’s
class, so that it can easily be accessed from any screen in your
application.
private final static String APPLICATION_KEY = "APP_KEY";
private LocalyticsSession _session = new LocalyticsSession(APPLICATION_KEY);
-
Add an accessor function to your main application class so this object may be
accessed from anywhere in your code.
public LocalyticsSession getLocalyticsSession().
{
return this._session;
}
-
Open the session and begin uploading.
Uploading should happen at the beginning of the app because this shows the
‘would you like to allow access to analytics.localytics.com’ dialog which the
user will see before they have a chance to begin an activity. This also provides
the uploader the maximum amount of time to complete if the wireless network is
slow. This is best done in the constructor of your
application.
LocalyticsSkeletonApp()
{
// open the session and begin uploading.
_session.open();
_session.upload();
pushScreen(new LocalyticsSkeletonAppScreen());
}
-
Finally, for every exit path in your application, you must close the session.
Regardless of the method you choose, remember to overload any
onClose() methods which could lead to an exit.
-
If you exit from within a screen, do this by calling the accessor created
in step 7.
((appClassName)UiApplication.getUiApplication()).getLocalyticsSession().close();
-
However, we recommend you maintain a single exit point inside the
application class which gets called anywhere the app terminates.
public void exit()
{
this._session.close();
System.exit(0);
}
-
Test your app. Launch the simulator (or even better, compile, sign, and run on
a real device), let the data upload, and view it on the webservice to make sure it is there.
Remember that the upload only happens when the session is started so any
events you tag will not get seen until you upload data a second time.
The uploader code assumes the simulator will be able to make a connection with
deviceSide=true; set. If you are testing in an MDS-only
environment, simply change USE_MDS_IN_SIMULATOR to
true in UploaderThread.java. This variable
has no impact on how the library behaves on an actual device.
Congratulations! You're integrated. Check out the data in your
Dashboard or get even more insights
when you start
tagging
events. Don't forget to test your app. Run it in an emulator, or on a real
device if possible.