Urban Airship Android Integration

Table of Contents

  • Getting Started
    • Integrate your project with Urban Airship SDK
    • Integrate Bluedot Point SDK in your Project
  • An interaction between Urban Airship SDK and Bluedot Point SDK
    • Start Urban Airship Services
    • Setup Bluedot Location Services
    • Use Case

Getting Started

Integrate your project with Urban Airship SDK

1. Modify your build.gradle to include Urban Airship and other dependencies.

repositories {
...
    maven {
        url  "https://urbanairship.bintray.com/android"
    }
}
dependencies {
  ...
    // Urban Airship SDK
    implementation 'com.urbanairship.android:urbanairship-fcm:9.3.1'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
}

UrbanAirship supports a few push providers: FCM, GCM, ADM. We recommend using Firebase. However, you can choose other.

2. Verify that the applicationId is set in the project’s build.gradle file.

android {
    ...
    defaultConfig {
        ...
        applicationId "com.example.application"
    }
}

3. Add the airshipconfig.properties to your application’s src/main/assets directory. (Note: You may have to create the src/main/assets directory.)

Download airshipconfig.properties pre-populated with your Urban Airship app key and secret or add it manually.

developmentAppKey = Your Development App Key
developmentAppSecret = Your Development Secret
 
productionAppKey = Your Production App Key
productionAppSecret = Your Production Secret
 
#Toggles between the development and production app credentials
#Before submitting your application to an app store set to true
inProduction = false
 
#LogLevel is "VERBOSE", "DEBUG", "INFO", "WARN", "ERROR" or "ASSERT"
developmentLogLevel = DEBUG
productionLogLevel = ERROR

fcmSenderId = FCM sender id

4. Start Urban Airship services by invoking takeOff at the entry point in the application. To do so, you need to have a class that extends Application class and set the name of that class for the application entry in AndroidManifest.xml.

<application android:name=".CustomApplication" ... />

Then, override the application’s onCreate to call UAirship.takeOff.

@Override
public void onCreate() {
   super.onCreate();
 
   UAirship.takeOff(this, new UAirship.OnReadyCallback() {
       @Override
       public void onAirshipReady(UAirship airship) {
 
           // Enable user notifications
           airship.getPushManager().setUserNotificationsEnabled(true);
       }
   });
}

Then, override the application’s onCreate to call UAirship.takeOff.

@Override
public void onCreate() {
   super.onCreate();
 
   UAirship.takeOff(this, new UAirship.OnReadyCallback() {
       @Override
       public void onAirshipReady(UAirship airship) {
 
           // Enable user notifications
           airship.getPushManager().setUserNotificationsEnabled(true);
       }
   });
}

5. Add the FCM Sender ID to your airshipconfig.properties. Your sender ID location is in the Cloud Messaging tab in the Firebace Developer Console. See the FCM Setup documentation for detailed instructions on setting up FCM Sender ID.

fcmSender = Your Firebase Sender ID
image

You need to add your Project’s Server API key and Package name in Urban Airship ( Settings > Services). See the FCM Setup documentation for detailed instructions on obtaining your API Key.

6. If there is no error then Build your project and you are ready to send your first test message.

Integrate Bluedot Point SDK in your Project

1. Add PointSDK-Android module to your build.gradle file

repositories { 
    ... 
    maven { 
        ...
        url "https://urbanairship.bintray.com/android" 
    } 
}
dependencies {
    ...
    implementation 'com.github.Bluedot-Innovation:PointSDK-Android:1.12.2'
}

2. Add required permissions in AndroidManifest.xml file

<!-- General Point SDK functionality -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<usus-permissiom android:name="android.permission.FOREGROUND_SERVICE" />

<!-- Required for Beacons integration -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

In addition to the above permissions, following services must be declared

<!-- General Point SDK functionality -->
<service
android:name="au.com.bluedot.point.net.engine.BlueDotPointService"
android:exported="false">
</service>

<service
android:name="au.com.bluedot.point.net.engine.DataJobScheduler"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE">
</service>

<!-- Required for Beacons integration -->
<service
android:name="au.com.bluedot.point.beacon.BlueDotBLEService"
android:exported="false">
</service>

<service android:name="au.com.bluedot.point.net.engine.DataJobScheduler" android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE" />

Interaction between Urban Airship SDK and Bluedot Point SDK

Start Urban Airship Services

 

1. Start Urban Airship services by overriding onCreate in your custom Application class

super.onCreate();
 
    UAirship.takeOff(this, new UAirship.OnReadyCallback() {
        @Override
      public void onAirshipReady(UAirship airship) {
 
          // Enable user notifications
          airship.getPushManager().setUserNotificationsEnabled(true);
      }
    });
}

or add Autopilot configuration to AndroidManifest.xml
<meta-data android:name="com.urbanairship.autopilot" android:value="com.urbanairship.Autopilot"/>

Setup Bluedot Location Services

1. Start PointSDK at the entry point in your application by overriding onCreate()

super.onCreate();
...
// start Point SDK
intcheckPermissionCoarse = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION);
intcheckPermissionFine = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION);
if(checkPermissionCoarse == PackageManager.PERMISSION_GRANTED && checkPermissionFine == PackageManager.PERMISSION_GRANTED) {
serviceManager = ServiceManager.getInstance(this);
if(!serviceManager.isBlueDotPointServiceRunning()) {
    // Setting Notification for foreground service, required for Android Oreo and above.
    // Setting targetAllAPIs to TRUE will display foreground notification for Android versions lower than Oreo
    serviceManager.setForegroundServiceNotification(createNotification(), false);
    serviceManager.sendAuthenticationRequest("Your Bluedot API key", this, false);
    }
}

else
{
    requestPermissions();
}

3. Implement Point SDK callback

@Override
public void onCheckIntoFence(FenceInfo fenceInfo, ZoneInfo zoneInfo, LocationInfolocationInfo, Map<String, String> customDataMap, boolean b) {
    ...
}

@Override
public void onCheckedOutFromFence(FenceInfo fenceInfo, ZoneInfo zoneInfo, int dwellTime,Map<String, String> customDataMap) {
    ...
}

@Override
public void onCheckIntoBeacon(BeaconInfo beaconInfo, ZoneInfo zoneInfo, LocationInfolocationInfo, Proximity proximity, Map<String, String> customDataMap, boolean b) {
    ...
}

@Override
public void onCheckedOutFromBeacon(BeaconInfo beaconInfo, ZoneInfo zoneInfo, int dwellTime,Map<String, String> customDataMap) {
    ...
}
image

Only Custom Actions defined for a Zone will trigger Check-in and Check-out callbacks.

Check-out does not apply to GEOLINE™.

Use Case

Objective: To trigger automated message pushed to user when their device checks in into Geofence or Beacons.

Setting Automated Message: Automated message to be setup via Urban Airship Dashboard, to trigger when a new event is posted.

Geofence or Beacon or GEOLINE™: Geographical boundaries , two or more real-world geographical points or BLE Beacons created in Bluedot Point Access Dashboard with Custom Action. (Note: Checkout does not apply to GEOLINE™)

 

@Override
public void onCheckIntoFence(FenceInfo fenceInfo, ZoneInfo zoneInfo, LocationInfo locationInfo, Map<String, String> customDataMap, boolean b) {
    CustomEvent.Builder builder = new CustomEvent.Builder("bluedot_place_entered");
    builder.setInteraction("location", zoneInfo.getZoneId());
    builder.addProperty("bluedot_zone_name", zoneInfo.getZoneName());
    if(customDataMap != null && !customDataMap.isEmpty()) {
        for(Map.Entry<String, String> data : customDataMap.entrySet()) {
            builder.addProperty(data.getKey(), data.getValue());
        }
    }

    CustomEvent event = builder.build();
    event.track();
}

@Override
public void onCheckedOutFromFence(FenceInfo fenceInfo, ZoneInfo zoneInfo, int dwellTime, Map<String, String> customDataMap) { {
    CustomEvent.Builder builder = new CustomEvent.Builder("bluedot_place_exited");
    builder.setInteraction("location", zoneInfo.getZoneId());
    builder.addProperty("bluedot_zone_name", zoneInfo.getZoneName());
    if(customDataMap != null && !customDataMap.isEmpty()) {
        for(Map.Entry<String, String> data : customDataMap.entrySet()) {
            builder.addProperty(data.getKey(), data.getValue());
        }
    }

    if(dwellTime != -1) {
        builder.addProperty("dwell_time", dwellTime);
    }

    CustomEvent event = builder.build();
    event.track();
}
@Override public void onCheckIntoBeacon(BeaconInfo beaconInfo, ZoneInfo zoneInfo, LocationInfolocationInfo, Proximity proximity, Map<String, String> customDataMap, boolean b) {
    CustomEvent.Builder builder = new CustomEvent.Builder("bluedot_place_entered");
    builder.setInteraction("location", zoneInfo.getZoneId());
    builder.addProperty("bluedot_zone_name", zoneInfo.getZoneName()); 
    if(customDataMap != null && !customDataMap.isEmpty()) { 
        for(Map.Entry<String, String> data : customDataMap.entrySet()) { 
            builder.addProperty(data.getKey(), data.getValue()); 
        } 
    } 

    CustomEvent event = builder.build(); 
    event.track();
} 

@Override public void onCheckedOutFromBeacon(BeaconInfo beaconInfo, ZoneInfo zoneInfo, int dwellTime,Map<String, String> customDataMap) {
    CustomEvent.Builder builder = new CustomEvent.Builder("bluedot_place_exited");
    builder.setInteraction("location", zoneInfo.getZoneId());
    builder.addProperty("bluedot_zone_name", zoneInfo.getZoneName());
    if(customDataMap != null && !customDataMap.isEmpty()) {
        for(Map.Entry data : customDataMap.entrySet()) {
            builder.addProperty(data.getKey(), data.getValue());
        }
    }

    if(dwellTime != -1) {
        builder.addProperty("dwell_time", dwellTime);
    }

    CustomEvent event = builder.build();
    event.track();
}
Created by Bluedot DevOps on February 24, 2018

Start the discussion