Set up Blueshift's Android SDK

This article provides information on how-to set up Blueshift's Android SDK to integrate your app with our platform.

Installing Blueshift's Android SDK into your Android App is pretty straightforward. Follow the step-by-step instructions provided below.

1. Firebase Cloud Messaging

Blueshift's Android SDK uses Firebase Cloud Messaging (FCM) to send push messages to your app. So you must first integrate it into your project. If you have already integrated it, skip this step.

Follow the documentation provided here to complete the FCM integration.

📘

We have a known issue with deprecation of FirebaseInstanceId class. This will be resolved in our upcoming releases. Keep an eye on this doc or our Github release page.

📘

According to this documentation, if you are using Firebase libraries with versions released on June 17, 2019 or later, then you must use Jetpack (AndroidX) libraries in your project. Otherwise, you can continue to use the older libraries that are supported. The minimum Firebase versions that the Blueshift Android SDK — version 2.0.2 or later — supports are: 16.0.6 (core) and 17.3.4 (messaging).

2. Get the Blueshift Android SDK

Blueshift's Android SDK is published to Maven Central repository. Ensure that you have mavenCentral() added inside the repositories section of your project level build.gradle file.

We have two variants of the SDK to support Google's Support libraries and AndroidX libraries. You can download the one that matches your choice of libraries by adding the appropriate line to your app level build.gradle file's dependencies section.

repositories {
  mavenCentral()
  google()
}

Blueshift Android SDK with Google Support Libraries

Maven CentralMaven Central

dependencies {
  // Blueshift Android SDK
  implementation "com.blueshift:android-sdk:$sdkVersion"
}

Blueshift Android SDK with AndroidX Libraries

Maven CentralMaven Central

dependencies {
  // Blueshift Android SDK
  implementation "com.blueshift:android-sdk-x:$sdkVersion"
  // ensure that you provide the right version number
}

3. Update AndroidManifest.xml

Permissions

<!-- Internet permission is required to send events, 
get notifications and in-app messages. -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Network state access permission is required to detect changes 
in network connection to schedule sync operations. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Location access permission is required if you want to track the 
location of the user. You can skip this step if you don't want to 
track the user location. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Firebase Cloud Messaging (FCM) Receiver

First time FCM Integration

If this is the first time that you are integrating FCM with your application, add the following lines of code into the AndroidManifest.xml file. This will enable the Blueshift Android SDK to receive the push notification sent from Blueshift servers via Firebase.

<service android:name="com.blueshift.fcm.BlueshiftMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Existing FCM Integration

If you have an existing FCM integration, let your FirebaseMessagingService class to extend BlueshiftMessagingService as mentioned below. This will enable the Blueshift Android SDK to receive the push notification sent from Blueshift servers via Firebase.

public class AwesomeAppMessagingService extends BlueshiftMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        if (BlueshiftUtils.isBlueshiftPushMessage(remoteMessage)) {
            super.onMessageReceived(remoteMessage);
        } else {
            /*
             * The push message does not belong to Blueshift. Please handle it here.
             */
        }
    }

    @Override
    public void onNewToken(String newToken) {
        super.onNewToken(newToken);

        /*
         * Use the new token in your app. the super.onNewToken() call is important
         * for the SDK to do the analytical part and notification rendering.
         * Make sure that it is present when you override onNewToken() method.
         */
    }
}

Install Referrer Tracking (Optional)

To automatically track the installation referrer, add the following lines inside the application tag

🚧

The app_install event occurs only when a user installs the app from the Play Store by clicking a referral URL. If the user navigates to the Play Store, searches for, and then installs the app, the app_install event is not triggered. As such, the number of app_installs captured by Blueshift might be lower than the actual app installs.

<receiver
    android:name="com.blueshift.receiver.AppInstallReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />

        <data android:scheme="package" />
    </intent-filter>
</receiver>

What’s Next

Now that you're done setting up the SDK in your app, it's time to include it in your code, configure it, and initialize it to start using its features. For more information about it, see:

Did this page help you?