Installation

Installation

Gradle

Ensure Maven Central is present in your project’s build.gradle:

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Then add the following compile statements to the dependencies section in your module’s build.gradle:

dependencies {
     // Existing dependencies may go here
     implementation 'com.google.code.gson:gson:2.8.5'
     implementation 'com.squareup.okhttp3:okhttp:3.11.0'
     implementation 'com.mindscapehq.android:raygun4android:3.0.6'
}

Then sync your project.

Maven

To your pom.xml, add:

<dependency>
    <groupId>com.mindscapehq.android</groupId>
    <artifactId>raygun4android</artifactId>
    <version>3.0.6</version>
</dependency>

In your IDE, build your project (or run mvn compile), then see the configuration section below.

With Ant, other build tools, or manually

Download the JAR for the latest version, as well as the Gson library and OkHttp3 library. Place these in a /lib folder in your project and add them to your project’s classpath.

Configuration and usage

In AndroidManifest.xml, add the following permissions beneath the manifest element:

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

Inside the application element, add the following:

<service
    android:name="main.java.com.mindscapehq.android.raygun4android.services.CrashReportingPostService"
    android:exported="false"
    android:permission="android.permission.BIND_JOB_SERVICE"
    android:process=":crashreportingpostservice"/>
<service
    android:name="main.java.com.mindscapehq.android.raygun4android.services.RUMPostService"
    android:exported="false"
    android:permission="android.permission.BIND_JOB_SERVICE"
    android:process=":rumpostservice"/>
<meta-data android:name="com.mindscapehq.android.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.

Add the following imports to the starting activity of your application:

import main.java.com.mindscapehq.android.raygun4android.RaygunClient;
import main.java.com.mindscapehq.android.raygun4android.messages.RaygunUserInfo;

In a central activity method (such as onCreate()), call the following:

RaygunClient.init(getApplicationContext());
RaygunClient.attachPulse(this);

If you wish to use Real User Monitoring without network performance logging, use the code below.

boolean withNetworkLogging = false;
RaygunClient.attachPulse(this, withNetworkLogging);

Provide a user identifier

By default, each user will be identified with a unique guid. If possible, we highly recommend providing your own unique identifiers for your users which can be done as follows. The first string parameter can be any unique user id you want - email address is just a recommended example.

RaygunClient.setUser(new RaygunUserInfo(email, firstName, fullName, email, null, false));

Real User Monitoring messages will be sent to Raygun as soon as the app starts up. So once you’ve set up Real User Monitoring in your app, run it up and go to your Real User Monitoring dashboard to see the data it collects. Of course Real User Monitoring is most valuable once your app is out there in the store.

Views

Real User Monitoring will automatically record information about views when attached. You can filter out the reporting of view information by view name.

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

Network calls

Once Real User Monitoring is enabled, Raygun4Android will automatically log the performance of network calls made with the following methods.

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

You can also manually log the timings of network calls using the following Raygun4Android API.

RaygunClient.sendPulseTimingEvent(RaygunPulseEventType.NETWORK_CALL, "GET https://raygun.com", 1234);

The name string can be whatever works best for you - the HTTP method and url is a recommended example. The duration is the milliseconds that you’ve measured the network call to take.

Details about the network calls that you log can be found in the Performance tab of your Real User Monitoring for mobile dashboard.

Filtering network calls

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" });