Skip to content
Doorbell.io

Android documentation

Add Doorbell to your Android app and open the feedback dialog from any activity.

  • Min SDK version 16
  • Maven Central
  • Latest version 0.4.9
View the SDK on GitHub

BasicsLink to this section

Doorbell requires a min SDK version of 16.

You can install Doorbell via Maven Central.

Include the following in your dependencies:

Gradle
implementation 'io.doorbell:android-sdk:0.4.9@aar'

Note: The SDK uses AndroidX components, so your app will have to be compatible with it.

In the activity where you want to use Doorbell, you'll need to import the library using:

Java
import io.doorbell.android.Doorbell;

MethodsLink to this section

There are many methods that you can call on the Doorbell object:

  • setEmail(String email)
  • setName(String name)
  • addProperty(String key, Object value)
  • track(String userID, String eventName, JSONObject attributes)
  • captureScreenshot()
  • enableNPSRatings()
  • disableNPSRatings()
  • enableShowOnShake()
  • disableShowOnShake()
  • setShakeSensitivity(int sensitivity)
  • resetProperties()
  • setTags(ArrayList<String> tags)
  • getDialogBuilder()
  • show()

And also you can access all the views in the AlertDialog with the following methods:

  • getMessageField()
  • getEmailField()
  • getNPSLabel()
  • getNPSField()
  • getNPSScoreLabelLow()
  • getNPSScoreLabelHigh()
  • getPoweredByField()

ExampleLink to this section

Java
// In your activity
int appId = YOUR-ID-GOES-HERE;
String apiKey = "KEY";

Doorbell doorbellDialog = new Doorbell(this, appId, apiKey); // Create the Doorbell object

doorbellDialog.setEmail("name@example.com"); // Prepopulate the email address field
doorbellDialog.setName("Philip Manavopoulos"); // Set the name of the user (if known)
doorbellDialog.addProperty("loggedIn", true); // Optionally add some properties
doorbellDialog.addProperty("username", 'manavo');
doorbellDialog.addProperty("loginCount", 123);
doorbellDialog.getEmailField().setVisibility(View.GONE); // Hide the email field, since we've filled it in already
doorbellDialog.setTags(new ArrayList<String>(Arrays.asList("tag1", "tag2")));

doorbellDialog.getDialogBuilder().setTitle("Dialog title");

// Capture and send a screenshot of the current activity,
// (only available on certain paid plans)
doorbellDialog.captureScreenshot();

// Enable NPS ratings (only available on certain paid plans)
doorbellDialog.enableNPSRatings();

// Track events in Doorbell, which can trigger the popup to appear
JSONObject attributes = new JSONObject();
attributes.put("key", "value");
doorbellDialog.track("user-123", "opened_app", attributes);

// Callback for when a message is successfully sent
doorbellDialog.setOnFeedbackSentCallback(new io.doorbell.android.callbacks.OnFeedbackSentCallback() {
    @Override
    public void handle(String message) {
        // Show the message in a different way, or use your own message!
        Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    }
});

// Callback for when the dialog is shown
doorbellDialog.setOnShowCallback(new io.doorbell.android.callbacks.OnShowCallback() {
    @Override
    public void handle() {
        Toast.makeText(context, "Dialog shown", Toast.LENGTH_LONG).show();
    }
});

// Callback for when there is an error, if you want to handle it separately instead of showing a Toast
doorbellDialog.setErrorCallback(new RestErrorCallback() {
    @Override
    public void error(String errorMessage) {
        // Handle message
        Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show();
    }
});

doorbellDialog.show();

Material Components ExampleLink to this section

Java
// If using Material Components, you can initialize Doorbell like this:
Doorbell doorbellDialog = new Doorbell(this, appId, apiKey, new MaterialAlertDialogBuilder(this));

Note: Valid as of SDK version 0.4.0

ScreenshotsLink to this section

As shown above in the example, the Android SDK can capture a screenshot of the current activity, and attach it to the message being submitted.

To make the most of this, please ensure that a button to send you a message is included on all activities on which a screenshot would be important.

You can also open Doorbell when the user shakes their device. See Shake gesture below.

Shake gestureLink to this section

You can configure Doorbell to be shown when the device is shaken.

You can configure this in each activity.

ExampleLink to this section

Java
import io.doorbell.android.shake.ShakeDetector;

public class MyActivity extends Activity {
    int appId = YOUR-ID-GOES-HERE;
    String apiKey = "KEY";

    protected Doorbell doorbellDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.doorbellDialog = new Doorbell(this, appId, apiKey);
        this.doorbellDialog.setShakeSensitivity(ShakeDetector.SENSITIVITY_MEDIUM);
    }

    @Override
    protected void onResume() {
        super.onResume();
        this.doorbellDialog.enableShowOnShake();
    }

    @Override
    protected void onPause() {
        super.onPause();
        this.doorbellDialog.disableShowOnShake();
    }
}