Installation

Raygun4Android supports all devices that match the following requirements.

  • minSdkVersion 16+
  • compileSdkVersion 28

Ensure jcenter() or mavenCentral() are present in your project’s build.gradle:

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

Then add the following to your module’s build.gradle:

dependencies {
    implementation 'com.raygun:raygun4android:4.0.0'
}

Initialisation

In your app’s AndroidManifest.xml, make sure you have granted Internet permissions. Beneath the <manifest> element add:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Inside the <application> element, add the following:

<service android:name="com.raygun.raygun4android.services.CrashReportingPostService"
         android:exported="false"
         android:permission="android.permission.BIND_JOB_SERVICE"
         android:process=":crashreportingpostservice"/>
<service android:name="com.raygun.raygun4android.services.RUMPostService"
         android:exported="false"
         android:permission="android.permission.BIND_JOB_SERVICE"
         android:process=":rumpostservice"/>
<meta-data android:name="com.raygun.raygun4android.apikey"
           android:value="PASTE_YOUR_API_KEY_HERE" />

Replace the value in <meta-data> with your API key, available from your Raygun dashboard under Application settings.

In a central activity (we suggest to use your common launch activity), call the following:

RaygunClient.init(application);
RaygunClient.enableRUM(activity);

The above exception handler automatically catches and sends all uncaught exceptions. You can create your own or send from a catch block by calling RaygunClient.send() and passing in the Throwable.

For an actual usage example, check out the sample application in the app module of the GitHub repository.


Unique user tracking

Raygun supports tracking the unique users who encounter bugs in your apps.

By default a device-derived UUID is transmitted. You can also add the currently logged in user’s data like this:

String userIdentifier = "12345";

RaygunUserInfo user = new RaygunUserInfo(userIdentifier);
user.setFirstName("User");
user.setFullName("User Name");
user.setEmail("a@b.com");

RaygunClient.setUser(user);

Any of the properties but identifier and isAnonymous are optional. The property isAnonymous will be set to true if the identifier is null or an empty string. There is also a constructor overload if you prefer to specify all in one statement and a convenience constructor to only set an identifier.

The identifier should be a unique representation of the current logged in user - we will assume that messages with the same identifier are the same user. If you do not set it, it will be automatically set to the device UUID.

If the user context changes, for instance on log in/out, you should remember to call setUser again to store the updated user identifier. If a user logs out and you want to use the default device identifier again, just create an empty RaygunUserInfo object without an identifier. In this case isAnonymous will be set to true.


Version tracking

If you want to track the version of your app with a crash report, you can do that in different ways:

  1. Set the versionName attribute on <manifest> in your AndroidManifest.xml to be of the form x.x.x.x, where x is a positive integer
  2. Set the version in the overloaded init method when initialising RaygunClient: public static void init(Application application, String apiKey, String version)
  3. Use the static setVersion method on RaygunClient class

The app’s version will then be sent with each message and you can then filter by version in the Raygun dashboard.


Views timing events

Once Real User Monitoring is enabled, the Raygun client will automatically report information about views. You can filter out the reporting of view information by view name using the following snippet.

RaygunClient.ignoreViews(new String[]{ "MainActivity" });

Network timing events

Once Real User Monitoring is enabled, the Raygun client will automatically report the performance of network calls made with the following methods.

  • java.net.HttpURLConnection
  • javax.net.ssl.HttpsURLConnection

If you don’t wish the performance of certain network requests to be logged, you can filter them out by URL.

RaygunClient.ignoreURLs(new String[]{ "raygun.com" });