Remotly get your error to your mail using Bugsense

Using the Android library

Integrating BugSense in your Android application is super easy!
If you are already using ACRA, read here for info on how to use BugSense as backend for ACRA data (it's a one-line change).

Install the BugSense Plugin

Before you install BugSense make sure that your app has the INTERNET permission turned on. If you have not added it, then simply add:

<uses-permission android:name="android.permission.INTERNET" /> 
outside the application tag in your AndroidManifest.xml.

Start with installing the BugSense library for Android phones. Just add bugsense-1.9.jar into your project. If you are using Eclipse, open the context menu of your project and select Properties > Java Build Path > Libraries. From here, you can add the jar file to your build path.

If you are using ant from console, just create a libs/ directory (in the same directory where AndroidManifest.xml exists) and copy the jar file inside the libs/ directory.
Then, import it into your main file:
import com.bugsense.trace.BugSenseHandler;
And finally just add the BugSenseHandler after setContentView only on your main/first activity and you are ready to go. Don't forget to use your Project API key, you'll find it in your dashboard.
public void onCreate(Bundle savedInstanceState) {
BugSenseHandler.setup(this, "YOUR_API_KEY");
// The rest of your code goes here
If you are creating a widget for Android, instead of adding the previous code, you must add this line inside your onEnabled function:
 public void onEnabled(Context context) {
BugSenseHandler.setup(context, YOUR_API_KEY);
Again, don't forget to use your Project API key you'll find in your dashboard. Now you can ship your application and stay cool. We will make sure you won't miss a bug.

Handled exceptions

BugSense handles automatically all unhandled exceptions but there are times when you need to handle the exception, log the error and continue. You can do this, easily:
try {
   // your code
   int a = 1/0; // this will raise an exception
} catch (Exception e) {
   BugSenseHandler.log(YOUR_TAG, e);
You can add a TAG (like PAYMENTS for example), so you can group similar exceptions.
The logging happens in the background, so the user won't notice any delay. You can also send, custom data like this:
try {
    throw new RuntimeException("Logging the event");
} catch (Exception e){
    Map<String, String> extraData = new HashMap<String,String>();
    extraData.put("your_key", "your_value");
    // example: extraData.put("email", "");
    BugSenseHandler.log("TEST_TAG", extraData, e);

Add metadata / custom variables

If you want to attach additional information that will be sent along with the crash, all you have to do is to call the following line wherever in your code. BugSenseHandler.addExtra("key1","value1")
You can also add a whole new array of data like this:
Map<String,String> extras = new HashMap<String,String>();

Fix notifications

Available on Indie and Premium plans

Lots of users don't upgrade their app (or they might be using a cracked version of your application, so they are missing the updates). When an error occurs that has been resolved in a newest version, the user will get a notification the moment the application crashes, prompting him to upgrade to the latest version.
With just one click, the user will be transferred to the market of your choice . Not only you can customize everything but you can also change the distribution channel in realtime! That means that you can have your alpha users, getting updates from dropbox or a ftp server and when you are ready, you can send them to the Market.
Setting up the service is trivial. Just fill the boxes in the "Fix notifications" tab, located in your dashboard with your messages and your market url and you are ready to go!
Now you can ship your application and stay cool. We will make sure your users you won't miss an update.

LOG CAT support

Available on Enterprise plans

Sometimes exceptions are not enough. You want to see the full log in order to have actionable data.
BugSense can get log output of a device during a crash. This way, you will now know exactly what was happening in the device just before the crash!
In order to be able to use this functionality you must follow two certain steps.
Firstly, make sure you have added the READ_LOGS permission to your manifest file.
<uses-permission android:name="android.permission.READ_LOGS" /> 

If you miss out to add the READ_LOGS permission, you will still be notified about the crash, but you will lose all the log data.
BugSense follows the same filtering mechanism LogCat uses. You can find a great tutorial here.


//Do not forget to setup the handler!
BugSenseHandler.setup(MyActivity.this, YOUR_API_KEY);
//Different ways to scratch the logs
//Log everything
//Log last 100 messages
//Log all the messages with priority level "warning" and higher, on all tags.
//Log the latest 100 messages with priority level "warning" and higher, on all tags.
BugSenseHandler.readLogs(100, "*:W");
//Log the latest 100 messages with priority level "warning" and higher, on all tags.
BugSenseHandler.readLogs(100, "*:W");
//Log all the messages from the ActivityManager and the Debug and higher of your application.
BugSenseHandler.readLogs(400, "ActivityManager:I MyApp:D *:S");

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:
@ReportsCrashes(formUri = "", formKey="")
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. ex.
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.

Don't forget to use your Project API key, you'll find it in your dashboard.

No comments:

Post a Comment