Android

Documentation - Pulse for Android

Setup instructions

1. Install the Raygun4Android provider

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

allprojects {
    repositories {
        mavenCentral()
    }
}

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

dependencies {
    // Existing dependencies may go here
    compile 'com.google.code.gson:gson:2.1'
    compile 'com.mindscapehq.android:raygun4android:3.0.0'
}

Then sync your project.

Alternatively, the Raygun4Android Pulse provider can be manually downloaded here.

2. Enable Pulse in your app

In AndroidManifest.xml, add these beneath the manifest element:

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

Then add the following within the application element, making sure to include your Raygun app API key. Your app API key is displayed when you create a new application in your Raygun account, or when you unlock Pulse for an existing app, or can be viewed in the "Application settings".

<service   android:name="main.java.com.mindscapehq.android.raygun4android.RaygunPostService"
           android:exported="false"
           android:process=":raygunpostservice"/>
<meta-data android:name="com.mindscapehq.android.raygun4android.apikey"
           android:value="YOUR_APP_API_KEY" />

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;

Finally, enable Raygun Pulse by adding the following code to the onCreate method of your starting activity:

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

If you wish to use Pulse without network performance logging, use the code below.

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

3. 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));

Done

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

Views

Pulse 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 Pulse 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.NetworkCall, "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 Pulse 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" });

Documentation missing?

If we don't have documentation about your desired topic, send us a message and we'll create it for you.