Airship Android Integration

Getting Started

Integrate Airship SDK into your App

Details on integrating the Airship SDK can be found on their documentation website here.

Integrate Bluedot Point SDK in your Project

To integrate Point SDK, please refer to the integration steps here

Interaction between Airship SDK and Bluedot Point SDK

Start Airship Services

1. Start 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

boolean locationPermissionGranted = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;

if (locationPermissionGranted) {
  serviceManager = ServiceManager.getInstance(this);
  if (!serviceManager.isBluedotServiceInitialized()) {
    InitializationResultListener resultListener = bdError -> {
    String text = "Initialization Result ";

    if (bdError != null) {
      text = text + bdError.getReason();
      Log.i("Bluedot", text);
    }
    else {
      startGeoTriggering()
    }
  }
  serviceManager.initialize("<Your Bluedot Project ID>", resultListener);
 }
}
else
{
   requestLocationPermissions();
}

2. Start Geo-triggering feature

public void startGeoTriggering() {
  // Start Geo-triggering feature
  GeoTriggeringService.builder()
    .start(this, geoTriggerError -> {
      if (geoTriggerError != null) {
        Log.i("Bluedot", "Error in starting GeoTrigger" + geoTriggerError.getReason())
      }
      else {
        Log.i("Bluedot", "GeoTrigger started successfully")
      }
  });
}

3. Receiving Geo-trigger events

Create a receiver in the Manifest to receive Geo-trigger events (such as entering a location):

<application android:label="@string/app_name" >
  <receiver
    android:name="my.package.ExampleGeoTriggerReceiver"
    android:enabled="true"
    android:exported="false"
  >
    <intent-filter>
      <action android:name="io.bluedot.point.GEOTRIGGER" />
    </intent-filter>
  </receiver>
</application>

Implement the receiver

public class ExampleGeoTriggerReceiver extends GeoTriggeringEventReceiver {
  @Override
  public void onZoneEntryEvent(@NotNull ZoneEntryEvent entryEvent, @NotNull Context context) {
    ...
  }

  @Override
  public void onZoneExitEvent(@NotNull ZoneExitEvent exitEvent, @NotNull Context context) {
    ...
  }
}
image

Exit does not apply to GEOLINE™.

Use Case

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

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

@Override
public void onZoneEntryEvent@NotNull ZoneEntryEvent entryEvent, @NotNull Context context) {
  CustomEvent.Builder builder = new CustomEvent.Builder("bluedot_place_entered");
  builder.setInteraction("location", entryEvent.getZoneInfo().getZoneId());
  builder.addProperty("bluedot_zone_name", entryEvent.getZoneInfo().getZoneName());
  Map<String, String> customData = entryEvent.getZoneInfo().getCustomData();

  if (customDataMap != null) {
    for (Map.Entry<String, String> data : customData.entrySet()) {
      builder.addProperty(data.getKey(), data.getValue());
    }
  }

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

@Override
public void onZoneExitEvent(@NotNull ZoneExitEvent exitEvent, @NotNull Context context) { {
  CustomEvent.Builder builder = new CustomEvent.Builder("bluedot_place_exited");
  builder.setInteraction("location", exitEvent.getZoneInfo().getZoneId());
  builder.addProperty("bluedot_zone_name", exitEvent.getZoneInfo().getZoneName());
  Map<String, String> customData = exitEvent.getZoneInfo().getCustomData();
  Int dwellTime = exitEvent.getDwellTime();

  if (customDataMap != null) {
    for (Map.Entry<String, String> data : customData.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