Android
Introduction
The Airbrake notifier for Android is designed to give you instant notification of any uncaught exceptions thrown from your Android applications.
Installation
Building from Source
To build a .jar file from source, make a clone of the airbrake-android
github repository and run:
ant package
This will generate a file named build/airbrake-android-<version>.jar.
Setting up your Android project
Download the Airbrake Jar of the build from source via
GitHub.
Copy the .jar file to your Android app’s libs/ folder.
Import the AirbrakeNotifier class in your app’s main Activity.
import com.loopj.android.airbrake.AirbrakeNotifier;
In your activity’s onCreate function, call AirbrakeNotifier.register to
begin capturing exceptions:
AirbrakeNotifier.register(this, "API_KEY");
Configuration
AirbrakeNotifier.register requires a context and an Airbrake API key to
be passed in, and optionally a third argument specifying the environment. The
environment defaults to ‘production’ if not set.
Notify from a try catch block
To notify Airbrake of non-fatal exceptions, or exceptions you have explicitly
caught in your app, you can call AirbrakeNotifier.notify. This call takes
exactly one argument, a Throwable, and can be called from anywhere in your
code. For example:
try {
// Something dangerous
} catch(Exception e) {
// We don't want this to crash our app, but we would like to be notified
AirbrakeNotifier.notify(e);
}