We’ve been working non-stop on the Instabug for Android SDK. Today we’re happy to tell you that Droid has a new friend!

When developing the SDK for Android apps we remained true to Instabug’s core axiom: simplicity of integration! It’s just a few steps to get the SDK working:

 

 

1. Acquire the SDK

 

For Gradle and Android Studio users, our Android SDK is published through Maven Central. All you need to do is add our dependency. If you’re still using Eclipse then don’t worry we, haven’t forgotten about you. We’ve created Eclipse projects that contain all the necessary JARs and resources to include in your application.

In your build.gradle file, add the following dependency in your dependencies block:

compile 'com.instabug.library:instabugsupport:1+'

 

Then click on the sync gradle files button. If you’re using the ActionBarSherlock library for implementing action bars then just replace “instabugsupport” with “instabugabs”. The versions for both artifacts are the same.

 

To be able to support both AppCompat V7 and ActionBarSherlock we had to split our library into three components:

  1. Instabug Core: This contains all the core functionality of the library and is included as a dependency for the two other components

  2. Instabug Support: This contains all helper activities and annotation activities used with the support library

  3. Instabug ABS: This contains all helper activities and annotation activities implemented using ActionBarSherlock activities

 

The SDK depends on some libraries as well:

  1. Android Support Library v4

  2. Volley

  3. Mime Craft

These dependencies are already defined through our Maven distribution. If you download the Eclipse SDK, you will already have the JAR files included in the downloaded project.

 

 

2. Request the proper permissions

Gradle users can skip all AndroidManifest.xml instructions as these are already handled by Android plugin’s manifest merger, so you can keep your own AndroidManifest.xml shorter.

 

Next we need to request the proper permissions for the SDK to work. This is done in the AndroidManfiest.xml file. The library requires the following permissions:

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

 

These are all pretty straight permissions, nothing special here.

 

 

3. Define the Instabug SDK components in your AndroidManifest.xml

 

Next, we define all required components for the SDK to work in the AndroidManifest.xml.

 

We start with the Annotation activity. This is what will allow Android app users to draw on the screenshot and add messages that can be sent to you.

<activity android:name="com.instabug.library.InstabugFeedbackActivity"
     android:windowSoftInputMode="adjustPan"
     android:theme="@style/YOUR_THEME"/>

 

Another point to note is that you have to set a theme for the annotation activity. The activity styles itself based on your Android app’s style. This allows the library to blend in with your user experience and your branding guidelines and not disrupt the user.

 

After defining the activity, we define a service “UploadCacheService”. This service is responsible for uploading all types of reports and screenshots to our servers.

<service android:name="com.instabug.library.network.UploadCacheService"/>

 

We also define a broadcast receiver to receive notifications on connectivity changes. The broadcast receiver starts the UploadCacheService as soon as a network connection has been established in order to upload all cached bug/crash reports.

<receiver android:name="com.instabug.library.network.InstabugNetworkReceiver">
     <intent-filter>
          <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
     </intent-filter>
</receiver>

 

 

4. Initialize the library

 

Your Application’s class file should look something like this:

package com.instabug.demo.demoapplication;
import android.app.Application;
import com.instabug.library.Instabug;
import com.instabug.library.InstabugFeedbackActivity;

public class DemoApplication extends Application {
     @Override
     public void onCreate() {
          super.onCreate();
          Instabug.initialize(this, "Your App Token Here")
                  .setShowIntroDialog(true, MyFirstContentActivity.class)
                  .enableEmailField(true,false)
                  .setEnableOverflowMenuItem(true);
     }
}

 

This initializes the Instabug SDK, tells the SDK to show the introduction dialog when an activity of type MyFirstContentActivity is started for the first time. It also enables the e-mail field in the feedback dialog form but specifies that it isn’t required. Finally, it sets the enable overflow menu item flag so that an item is added to the action bar overflow menu with “Send Feedback”.

 

There are many other customization options and we recommend you go through them in the library’s documentation page.

 

 

5. Register your activities with Instabug

 

This is the final step before you can start receiving bugs in your dashboard. If you’re minSdkVersion 14, you don’t really need to do this step as we can automatically detect activity life cycles. However, for SDK levels less than 14, we need to keep track of the displayed activity. We’ve already created helper activity classes, so you don’t need to worry about any of that. All you have to do is just extend them.

  • InstabugActionBarActivity : This extends android.support.v7.app.ActionBarActivity

  • InstabugActivity : This extends android.app.Activity

  • InstabugFragmentActivity : This extends android.support.v4.app.FragmentActivity

  • InstabugExpandableListActivity : This extends android.app.ExpandableListActivity

  • InstabugListActivity : This extends android.app.ListActivity

  • InstabugPreferenceActivity : This extends android.preference.PreferenceActivity

 

These helper activities also contain helper code to make certain features of the SDK work, including things like the two finger swipe gesture invocation. If, for some reason, you’re unable to extend our Activity classes, you can add the following code to your Activity to register it with our SDK:

@Override
protected void onResume() {
    super.onResume();
    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){
        Instabug.getInstance().setActivity(this);
    }
}

@Override
protected void onPause() {
    super.onPause();
    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){
        Instabug.getInstance().activityPaused(this);
    }
}

 

Another benefit of using our base activity helpers is automatic user step detection. This allows us to send you with every bug report the detailed log of step-by-step user actions. However, if you can’t extend our base activities then no problem, you can do this yourself using our TouchEventDispatcher class. All you have to do is add the following code in your base activity:

private TouchEventDispatcher dispatcher = new TouchEventDispatcher();

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    dispatcher.dispatchTouchEvent(this,ev);
    return super.dispatchTouchEvent(ev);
}

 

 

Congratulations! You have now successfully integrated the Instabug SDK for Android apps. It’s time to get shaking and start fixing those nasty bugs!

If you have any questions please feel free to e-mail us at contactus@instabug.com.

  • heh great to hear!

  • diensh

    Hello , want to set the instabug in my cordova [phonegap] project any help for that ?

    • Moataz Soliman

      @diensh:disqus Sure, please send us an email to contactus@instabug.com

    • cpcbell

      I’ve had success following these instructions, doing them after my ionic/cordova build using Android Studio. Make sure to add an AppCompat theme to your AndroidManifest.xml.

      For iOS, there is an old instabug cordova plugin that works by adding a method to your app.js. It does not work as well as adding instabug after the cordova build using Xcode.

      When I have some time I’m going to document the procedure.

  • Bob

    I wanted to read again , thank you!