Android

Integrate the Colocator Android library into your native Android app

Adding the dependency

  1. Add the Crowd Connected repository to your Gradle build file
repositories {
    jcenter()
    maven { url "http://maven.crowdconnected.net/" }
}
  1. Add the library to your dependencies
api 'net.crowdconnected.androidcolocator:colocator:2.7.7'

Getting Permission

Location permission should be requested within your app onboarding process. To increase location opt-ins explain the user how location data will be used, such as sending them relevant push notifications. Read more on maximising location opt-ins

ActivityCompat.requestPermissions(thisActivity, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION }, 0);

Configure the Foreground Service

To persistently gather data in the background a Foreground Service is required. The library will dynamically turn the Foreground Service on/off as needed.

Please provide an icon and some text for the Foreground Service notification.

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String channelID = "YOUR_CHANNEL_ID";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
    NotificationChannel channel = channel = new NotificationChannel(channelID,
            "Channel Name", 2);
    channel.setDescription("Channel description");
    notificationManager.createNotificationChannel(channel);
}
CoLocator.setServiceNotificationInfo(this.getApplication(), "Enjoy the event!", R.drawable.colocator_icon, channelID);

Enabling Location Gathering

If the user has granted Location Permission start the Colocator library

CoLocator.start(this.getApplication(), YOUR_APP_KEY);

Disabling Location Gathering

If required you can stop the library

CoLocator.instance().stop();

Sending an Alias

Aliases are key-value pairs. They are primarily used to send alternative IDs for a device, for example a unique Push Notification identifier. Go to the Push Notification Integrations page for more details

CoLocator.instance().addAlias("YOUR_KEY", "YOUR_VALUE");

Indoor Location Service

For indoor location and positioning, a few more steps need to be implemented. Bluetooth is also required for this functionality

Location Callbacks - Only for Indoor Navigation Purposes

The latest location can be sent back to the device either as a one-off or a stream of updates. This is primarily used for displaying the location of the device on a map.

Request one location:

CoLocator.instance().requestLocation(new LocationCallback() {
    @Override
    public void onLocationReceived(LocationResponse location) { 
      // Your code here
    }
    @Override
    public void onLocationsReceived(List<LocationResponse> locations) { }
});

Request a stream of location updates:

CoLocator.instance().requestLocation(new LocationCallback() {
    @Override
    public void onLocationReceived(LocationResponse location) { }
    @Override
    public void onLocationsReceived(List<LocationResponse> locations) {
      //Your Code here
     }
});

LocationResponse object contains “floor” field starting with SDK v2.7.0

Stopping Location Updates

Please make sure you unregister from location callbacks when the user is not using the indoor map screen or navigation.

This is important for battery and performance optimization.

Stop the stream of updates:

CoLocator.instance().unregisterLocationListener();