What you will learn

This tutorial will teach you how to generate a notification thanks to Connecthings' Mobile SDK, when a beacon is detected around a user's mobile phone.

Pre-requisites - What you need to get started

  • A Nexus Account: the SDK is available through a private Nexus. You should have received an email with your user account, including a link to create a password
  • Your SDK user information: in order to initialize the Mobile SDK, you must have received a User Name, a Password and a Company Key
  • A BLE beacon: a BLE beacon configured on your account is mandatory to test the application
  • An Android Device: you need a compatible Bluetooth Low Energy Android device that is able to detect beacons
  • The Android Studio application: you must have downloaded Android Studio from the Android Developpers’ website
  • You must have completed the 5 minutes QuickStart Tutorial.

Step 1: Clone the beacon-tutorial repository

  • Clone the beacon-tutorial repository
git clone https://github.com/Connecthings/sdk-tutorial.git
  • Open the android>beacon>2-Notification>Starter project with Android Studio

Step 2: Configure the SDK

  • Open the class ApplicationNotification
  • Configure your SDK with:
    • the UUID of your beacon
    • the appropriate Adtag Environment
    • your login, password, and company details you received from Connecthings

Step 3: About the auto Beacon Notification

The SDK comes with a default implementation of the Beacon Notification, the notification displayed when a beacon is detected around a user's mobile phone.

Personalize the Beacon Notification icon

You can personalyse the Beacon Notification icon, adding to your drawable resources folder an image named:

  • icon_beacon_notification_android4 untill Android 4.
  • icon_beacon_notification for Android 5 and above.

Disable the Beacon Notifications

You can disable the beacon notifications through this code :


Step 4: Create your first notification

This step is only requiered if you want your application to completly personalize the beacon notification.

  • Implement the BeaconNotification interface, with the method createNotification in the ApplicationNotification class
public class ApplicationNotification extends Application implements BeaconNotification

  public static final int NOTIFICATION_BEACON_ID = 1;

  public void onCreate(){
    //initialisation of the SDK

  public int createNotification(BeaconContent beaconContent) {
    //to create your notification

  • Register the class that implements the BeaconNotification interface in the AdtagBeaconManager


The AdtagBeaconManager supports only one BeaconNotification interface

public class ApplicationNotification extends Application implements BeaconNotification

  public void onCreate(){
    //initialisation of the SDK
    // Register the BeaconNotification Interface
  • Implement a local notification based on the BeaconContent
public int createNotification(BeaconContent beaconContent) {
	Log.d(TAG, "create notification");
        //example of notification code
	        mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
	notifyIntent.setClass(getApplicationContext(), MainActivity.class);
        notifyIntent.putExtra(MainActivity.FROM_NOTIFICATION, true);

        PendingIntent intent = PendingIntent.getActivity(this, 0,
                    notifyIntent,  PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder(this);
        Build the title and the description of the notification 
        mNotificationBuilder.setVibrate(new long[]{1000, 1000 ,1000});
        mNotificationManager.notify(NOTIFICATION_BEACON_ID, mNotificationBuilder.build());


The BeaconContent object contains the content associated to the beacon in Adtag.

The BeaconContent object has 2 methods to retrieve the default content for a notification:

  • BeaconContent.getNotificationTitle(): retrieves the title of the notification
  • BeaconContent.getNotificationDescription(): retrieves the description of the notification

You can also generate your own text for the title and description of the notification, based on other categories & fields, using the method BeaconContent.getValue(CATEGORY, FIELD).

For example, BeaconContent.getValue("LINE", "DIRECTION") allows to retrieve the DIRECTION field of the LINE category.

Step 5: Start testing

If your beacon is already emitting, you must stop/restart the emission process in order to simulate a new region entry for the smartphone, and generate a notification.

There are 2 solutions to stop/restart the emission process:

  • You can put the beacon inside a microwave (but don't start it!)
  • You can remove the battery from the beacon (in that case, depending on the model, it can take up to 30 seconds for the beacon to start emitting again when you put the battery back)
  1. From Android Studio, launch the installation of the application you have just built on your mobile phone.

  2. On Android 6 and above, when the application starts, a popup asks for permission to access your phone location: grant it!

  3. Put the application in the background

  4. Remove the beacon from the microwave or put the battery back.

  5. Wait for a few seconds (maximum 1 minute)

  6. Click on the notification that has appeared on your screen just for fun.


On some phones with Android 6 and above, it is necessary to enable location on the phone to enable beacon detection when the application is in the background.