Guide: Android: Crash Reports and Usage Monitoring:

Well you reached a step where you have completed your application and want
to test it or even publish it to the Google Play store. At this point (It’s strongly recommended
to do that even before that) it’s very important to integrated some sort of crash reports
service in your application and could be very useful to integrate some kind of usage
monitoring system as well.

So, today I’m going to talk about those features and more specifically I’m going to talk
about integration of two crash report services:

1. Crittercism
2. ACRA with BugSense back-end.

Both of those services can be used for free, but got paid programs as well.
I’m going to talk about one usage monitoring system as well named:
3. Flurry.
Lets start with the crash reports. So how is it done:

1. Well for Crittercism the deal is very simple, head to their site: www.crittercism.com,
and sign in. You will need to download the jar file from Documentation for Android section.
Once you did that and added the jar file to the /libs folder of your project you are ready to start
configuring it. Open your Apps section and create an application for which you would like to
receive crash reports. Press the:

Untitled

button, and enter the application details. When you finish press the REGISTER APP button at
the bottom of the page. Open your Apps page again and you will see the newly
added application under the Registered Apps section. Click on the app name to enter
it’s configurations and go to the Settings page (red), under “To initiate Crittercism for this
Application:”
you will find a row of code (green) you will have to integrate in your application
in order for the crash reports service to work:

Untitled5

You should integrate this line in the first Activity of your application in the onCreate() method:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Crittercism.init(getApplicationContext(), "516a6c4e46b7c26e6f000002");
    // rest of code here...
}

Add this Activity to the Manifast file:

<activity android:name="com.crittercism.NotificationActivity"/>

Finally you need to add the following three permissions to your Manifest file:

<!--  Internet Permission  -->
<uses-permission android:name="android.permission.INTERNET"/>
<!--  Crittercism Permissions  -->
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.GET_TASKS"/>

2. The second crash reporting service is greatly popular among Android developers:
Application Crash Report for Android or ACRA in short. up until not long ago
this service was used with Google Doc back-end to store the crash logs. this use of
Google Doc have became deprecated by Google, and they have asked developers nicely
not to use their service for this purpose.

So I searched for another back-end service that will work with ACRA and found out that
BugSense provide this kind of service. What you need to do as before is to head
to their site and sign up. Next, you will receive a dashboard screen, in it create a new
project that will represent the project you want to receive error reports for. Press the:

add project

button, and enter the application details like: Project Name, Billing Account, Platform (Technology) and another application details. Open your My projects page again and you will
see the newly added application:

new project

You can see that with the new project you receive an ApiKey(red) that you will use next to integrate ACRA in your project. To do that first head to acra.ch and download the
last .jar file from the Quick Setup section. As before add the jar file to the /libs folder of your project.

Now you can start integrate ACRA in your code, all you need to do is to add 2 lines to your application class:

import org.acra.*;
import org.acra.annotation.*;

@ReportsCrashes(formUri = "http://www.bugsense.com/api/acra?api_key=1e76b702", formKey="")
public class MyApplication extends Application 
{
    @Override
    public void onCreate() 
    {
        // The following line triggers the initialization of ACRA
        super.onCreate();
        ACRA.init(this);
        // rest of code here...
    }
}		

So as you can see you need to add the @ReportsCrashes annotation right before the class
definitions, where you would replace the api_key, with the key you were given from BugSense
when you registered your app. Second line would be:

ACRA.init(this);

to initialize ACRA monitoring. As with the first crash service don’t forget to add here the internet permission as well:

<!--  Internet Permission  -->
<uses-permission android:name="android.permission.INTERNET"/>

3. Now for the usage monitoring system: Flurry:
As with the other two services, we need to register so head to www.flurry.com, sign up for
the service, and open the Applications tab in your dashboard screen. click the Add a New Application option from the up-right corner, choose the platform of your project (Android in our case), pick a name for the project and select it’s category. Finally press the Create App button.

Next, you will receive the following screen:
flurry

Here as you can see you receive Your unique application key (1) and you have a button to
download the relevant SDK file for you platform (2). Download the SDK and as before integrate
it into the /libs folder of your application. Now for Flurry integration you need to add in each Activity of your application were you want to monitor user actions, those lines to start and stop monitoring:

@Override
protected void onStart()
{
    super.onStart();
    FlurryAgent.onStartSession(this, "65KYTTCTDCMT7J69S7XT");
}
	 
@Override
protected void onStop()
{
    super.onStop();		
    FlurryAgent.onEndSession(this);
}

To monitor an event you should add this line in the relevant position in your code:

FlurryAgent.onEvent("Event text");

If you want to monitor parameters as well then you need to pass a HashMap of parameters to the FlurryAgent like this:

final HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("String key", "String value");
FlurryAgent.logEvent("Text relevant to parameters", parameters);

As before, don’t forget to add the internet permission to your project:

<!--  Internet Permission  -->
<uses-permission android:name="android.permission.INTERNET"/>

And that it. Now you can and should monitor your application for errors and usage.
Enjoy and stay tuned.

One response to this entry

  • Hilary Cook Says:

    Hi there,

    I’m from http://raygun.io which has released an open source Android provider recently and was wondering if you’d be interested in giving the service a go! Get in contact via email if you’d like an account.

    Thanks!

    Posted on November 7th, 2013 at 12:47 am Reply | Quote

Leave a comment