Fork me on GitHub

Android

Download & install the SDK

Requirements
Android SDK 1.6 (Version 4) or later

  • Your first step is to copy the bugsense-3.2.2.jar (Release Notes) or_use Maven into your project’s libs folder. (If this folder do not exist, you have to create it.) Import it to your project by adding the following line at the top of your Activity's class file: import com.bugsense.trace.BugSenseHandler; Make sure you also add the line <uses-permission android:name="android.permission.INTERNET" />
    to your app's AndroidManifest.xml file. BugSense uses this permission to send the crash reports and performance metrics.
  • Next step is to add the BugSenseHandler in your activity before setContentView. Then you are ready to go!

The InitAndStartSession method installs the BugSense exception handler and the performance monitor. It then sends all the previously saved crash reports and performance metrics. At the same time, it starts a new session for your activity.


Here’s an example on how to use the InitAndStartSession: BugSenseHandler.initAndStartSession(MyActivity.this, "YOURAPIKEY");

Whenever you want to close the session, you can use the closeSession method as follows: BugSenseHandler.closeSession(MyActivity.this);

Close session will close the current session, offering better tracking of the sessions for your users.


If you want to manually flush all the saved data, use the BugSenseHandler.flush(Context) method:BugSenseHandler.flush(MyActivity.this);

Features

Add Extra Data

You have the option to add extra custom information to the crash reports. In order to do this, use the crash extra map.

Use the addCrashExtraData method below to add key value pairs to the extra map:

If you want to add your custom data as a map, use the addCrashExtraMap method:

Removing a value from the crash extra data is even simpler than adding one, with the removeCrashExtraData method. UseBugSenseHandler.removeCrashExtraData(Key) for example: BugSenseHandler.removeCrashExtraData("difficulty");

You can get the extra data map by using the BugSenseHandler.getCrashExtraData method.

If you want to clear the extra data completely, use the clearCrashExtraData method:BugSenseHandler.clearCrashExtraData();

Log Handled Exceptions

BugSense also gives you the ability to log handled exceptions, for example:

If you want to add information, you can replace the sendException method with the sendExceptionMessage method: BugSenseHandler.sendExceptionMessage("level", "second level", ex);

Alternatively you can use multiple key values using a HashMap with the sendExceptionMap method:

Breadcrumbs

By adding breadcrumbs to your code you can easily see the trail the user followed before getting the crash. Just add the following API call at the points if interest in your code.

BugSenseHandler.leaveBreadcrumb("PointA");

ProGuard support

If you are using ProGuard, you should add the following line to your ProGuard configuration file to exclude BugSense from being obfuscated.-keep public class com.bugsense.*

LogCat Support

Available on Enterprise plans

If you want to send the LogCat output with your exceptions, add the line <uses-permission android:name="android.permission.READ_LOGS" />
to your app's AndroidManifest.xml file. BugSense uses this permission to read the LogCat output. (Keep in mind that the logcat output may contain sensitive user information from other applications.)

In order to enable the LogCat logging, you can use the setLogging(Boolean) method. You can also restrain the number of the lines or the filter using the following methods:

BugSense by default sends the last 5000 lines with no filter. Filtering uses the exact same filtering mechanism as LogCat uses. You can find documentation here.

Sending custom events

If you want to log custom events, use the sendEvent(String) method of BugSenseHandler as shown below:
BugSenseHandler.sendEvent("button1 pressed");

Localize Fix Notifications

In order to localize the fix notification, use the setLocalizedNotification method passing the Strings for the ticker, the title and the message. For example: BugSenseHandler.setLocalizedNotification("Mi app", "Lo hemos corregido", "Por favor, actualice su aplicacion, este error ha sido corregido!");

BugSense and ACRA

  • If you are using ACRA 4.x, you can use BugSense as your backend.

    The only change you need to do is specify in formUri BugSense's url and your API key:

  • Custom Data
    If you want to send Custom Data with ACRA you should send data in a key value format. ex.key1=value1
    key2=value2
    key3=value3
    You can also tag an exception if you add a key named "tag" in the Custom Data, e.g ErrorReporter.getInstance().putCustomData("tag", "audio player");
  • ProGuard and ACRA
    There are some issues with using ProGuard and ACRA. We advise you to read the official ACRA wiki about this.

Sign in with Google

Forgot your password?