Initial SDK Setup

Installing the Braze SDK will provide you with basic analytics functionality as well as a working in-app slideup message with which you can engage your users. Note that the Android SDK file size is 763 KB.

Android SDK Integration

Braze is in the process of sunsetting formal support for the Eclipse IDE as Google is sunsetting support for the Eclipse Android Developer Tools Plugin. If you need assistance with your Eclipse integration prior to migration, please email Support for assistance.

Step 1: Integrate the Braze Library

The Braze Android SDK can optionally be integrated without UI components. However, In-App Messaging, the News Feed, and Feedback will be rendered inoperable unless you pass the custom data to a UI solely of your design. Additionally, push notifications will not work because our BroadcastReceiver that handles push is in the UI library. Please note that these UI elements are open source and fully customizable. We strongly recommend integration of these features. Please refer to the Braze Academy for the benefits of using the Braze News Feed, In-App Message, and Feedback UI.

Basic Integration

In order to access Braze’s messaging features, you must integrate the UI library. Please see the following directions to integrate the UI library depending on your IDE:

Using Android Studio

Step 1: Add our repository

In your top-level project build.gradle, add:

1
2
maven { url "https://appboy.github.io/appboy-android-sdk/sdk" }
maven { url "https://maven.google.com" }

as repositories under allprojects -> repositories.

For example:

1
2
3
4
5
6
7
allprojects {
  repositories {
    jcenter()
    maven { url "https://appboy.github.io/appboy-android-sdk/sdk" }
    maven { url "https://maven.google.com" }
  }
}

Alternatively, you may install the android-sdk-ui as an AAR file to your local maven repository. See the SDK Readme for details.

See the Android Support Library Setup instructions for more information on the google maven repository.

Step 2: Add Braze dependency

See the following example in our Hello Braze example project:

The below example shows where to place the dependency line in your build.gradle. Note that the version used in the example below uses an old version. Please visit Braze Android SDK Releases for the most up to date version of the Braze Android SDK.

MavenScreen2

Step 3: Perform Gradle Sync

Be sure to perform a Gradle Sync to build your project and incorporate the dependency additions noted above.

GradleSync

Step 2: Configure the Braze SDK in appboy.xml

Now that the libraries have been integrated, you have to create an appboy.xml file in your project’s res/values folder. If you have a custom endpoint or are on a specific data cluster, you need specify the endpoint in your appboy.xml file as well. The contents of that file should resemble the following code snippet:

Be sure to substitute the API key found within the App Settings page of the Braze dashboard for REPLACE_WITH_YOUR_API_KEY. To find out your specific cluster or custom endpoint, please ask your Customer Success Manager or open a support ticket.

1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="com_appboy_api_key">REPLACE_WITH_YOUR_API_KEY</string>
<string translatable="false" name="com_appboy_custom_endpoint">YOUR_CUSTOM_ENDPOINT_OR_CLUSTER</string>
</resources>

Step 3: Add Required Permissions to Android Manifest

Now that you’ve added your API key, you need to add the following permissions to your AndroidManifest.xml:

1
2
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

With the release of Android M, Android switched from an install-time to a runtime permissions model. However, both of these permissions are normal permissions and are granted automatically if listed in the app manifest. For more information, visit Android’s permission documentation.

Implementation Example

See the appboy.xml in the Droidboy sample app for an implementation example.

Step 4: Tracking User Sessions in Android

Activity Lifecycle Callback Integration (API 14+)

This feature is supported on API 14 and above. Calls to openSession(), closeSession(),ensureSubscribedToInAppMessageEvents(), and InAppMessageManager registration are optionally handled automatically. See the HelloBraze sample application for a full example.

Instructions

Add the following code to the onCreate() method of your Application class:

1
registerActivityLifecycleCallbacks(new AppboyLifecycleCallbackListener());

You may refer to the following example inside Hello Braze:

ActivityLifecycleCallbackIntegration

The first argument instructs the listener to handle openSession() and closeSession() calls. The second argument instructs the listener to handle registerInAppMessageManager() and unregisterInAppMessageManager() calls.

See the javadoc for more information. Please note that any non-standard manual session integration is not fully supported.

Step 5: Optional Custom Endpoint Setup

If you have been set up with a custom endpoint your Customer Success Manager will advise you of the correct address. To update the default endpoint in your integration of the Braze SDKs please add the following code:

Android

Add the following code to your appboy.xml:

1
<string translatable="false" name="com_appboy_custom_endpoint">YOUR_CUSTOM_ENDPOINT_OR_CLUSTER</string>

SDK Endpoint configuration via appboy.xml is available starting with Braze Android SDK v2.1.1.

SDK Integration Complete

Braze should now be collecting data from your application and your basic integration should be complete. Please see the following sections in order to enable custom event tracking, push messaging, the news-feed and the complete suite of Braze features.

WAS THIS PAGE HELPFUL?