Android

Features

The Raven Android SDK is built on top of the main Java SDK and supports all of the same features, configuration options, and more.

Events will be buffered to disk (in the application’s cache directory) by default. This allows events to be sent at a later time if the device does not have connectivity when an event is created. This can be disabled by setting the DSN option raven.buffer.enabled to false.

An UncaughtExceptionHandler is configured so that crash events will be stored to disk and sent the next time the application is run.

The AndroidEventBuilderHelper is enabled by default, which will automatically enrich events with data about the current state of the device, such as memory usage, storage usage, display resolution, connectivity, battery level, model, Android version, whether the device is rooted or not, etc.

Installation

Using Gradle (Android Studio) in your app/build.gradle add:

compile 'com.getsentry.raven:raven-android:7.8.6'

For other dependency managers see the central Maven repository.

Usage

Configure your Sentry DSN (client key) in your AndroidManifest.xml:

<application>
  <meta-data
    android:name="com.getsentry.raven.android.DSN"
    android:value="https://publicKey:secretKey@host:port/1?options" />
</application>

Your application must also have permission to access the internet in order to send event to the Sentry server. In your AndroidManifest.xml:

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

Then, in your application’s onCreate, initialize the Raven client:

import com.getsentry.raven.android.Raven;

// "this" should be a reference to your main Activity
Raven.init(this.getApplicationContext());

Now you can use Raven to capture events anywhere in your application:

// Send a simple event to the Sentry server
Raven.capture("Error message");

try {
    something()
} catch (Exception e) {
    // Send an exception event to the Sentry server
    Raven.capture(e);
}

// Or build an event manually
EventBuilder eventBuilder = new EventBuilder()
                              .withMessage("Exception caught")
                              .withLevel(Event.Level.ERROR);
Raven.capture(eventBuilder.build());