Utility Methods

Set DeviceToken

The Cyprinus SDK is capable of sending push notifications to your users. Add Firebase to your Android project to get the device token.
Kotlin
Java
1
Roam.setDeviceToken("FCM DeviceToken")
Copied!
1
Roam.setDeviceToken("FCM DeviceToken");
Copied!

Get DeviceToken

To get the FCM DeviceToken from the SDK.
Kotlin
Java
1
Roam.getDeviceToken()
Copied!
1
Roam.getDeviceToken();
Copied!

Check location permission

Check whether your App has location permission. Returns a boolean, which is true if the location permission has been granted, and false otherwise.
Kotlin
Java
1
Roam.checkLocationPermission()
Copied!
1
Roam.checkLocationPermission();
Copied!

Check location services

Check whether the device has location services enabled. Returns a boolean, which is true if the location services are on, and false otherwise.
Kotlin
Java
1
Roam.checkLocationServices()
Copied!
1
Roam.checkLocationServices();
Copied!

Check Background Location Permission

Check whether your App has background location permission. Returns a boolean, which is true if the background location permission has been granted, and false otherwise.
Kotlin
Java
1
Roam.checkBackgroundLocationPermission()
Copied!
1
Roam.checkBackgroundLocationPermission();
Copied!

Request Location Permissions

Call this method to request the user to enable location permissions.
Kotlin
Java
1
Roam.requestLocationPermission(this)
Copied!
1
Roam.requestLocationPermission(this);
Copied!
Kotlin
Java
1
override fun onRequestPermissionsResult(requestCode: Int, permissions:
2
Array<String>, grantResults:IntArray) {
3
when (requestCode) {
4
Roam.REQUEST_CODE_LOCATION_PERMISSION->
5
if (grantResults[0] ==PackageManager.PERMISSION_GRANTED) {
6
....
7
} else if (grantResults[0] ==PackageManager.PERMISSION_DENIED) {
8
....
9
}
10
}
11
}
Copied!
1
//Callback from request location permission method.
2
@Override
3
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
4
switch (requestCode) {
5
case Roam.REQUEST_CODE_LOCATION_PERMISSION:
6
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
7
...
8
} else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
9
...
10
}
11
break;
12
}
13
}
Copied!

Request Location Services

Call this method to enable location services.
Kotlin
Java
1
Roam.requestLocationServices(this)
Copied!
1
Roam.requestLocationServices(this);
Copied!
Kotlin
Java
1
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
2
super.onActivityResult(requestCode, resultCode, data)
3
if (requestCode == Roam.REQUEST_CODE_LOCATION_ENABLED) {
4
....
5
}
6
}
Copied!
1
//Callback from request location services method.
2
@Override
3
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
4
super.onActivityResult(requestCode, resultCode, data);
5
if (requestCode == Roam.REQUEST_CODE_LOCATION_ENABLED) {
6
}
7
}
Copied!

Request Background Location Permission

Call this method to request the user to enable background location permissions.
Kotlin
Java
1
Roam.requestBackgroundLocationPermission(this)
Copied!
1
Roam.requestBackgroundLocationPermission(this);
Copied!
Kotlin
Java
1
override fun onRequestPermissionsResult(requestCode: Int, permissions:
2
Array<String>, grantResults: IntArray) {
3
when (requestCode) {
4
Roam.REQUEST_CODE_BACKGROUND_LOCATION_PERMISSION->
5
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
6
...
7
}
8
else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
9
...
10
}
11
}
12
}
Copied!
1
//Callback from request background location permission method.
2
@Override
3
public void onRequestPermissionsResult(intrequestCode, Stringpermissions[],
4
int[] grantResults) {
5
switch (requestCode) {
6
case Roam.REQUEST_CODE_BACKGROUND_LOCATION_PERMISSION:
7
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
8
...
9
}
10
else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
11
...
12
}
13
break;
14
}
15
}
Copied!

Check Location Tracking

Check whether location tracking is started or not. This method returns a boolean value.
Kotlin
Java
1
Roam.isLocationTracking()
Copied!
1
Roam.isLocationTracking();
Copied!

Update Current Location

Using the updateCurrentLocation method, you can update the user's current location, you can set the accuracy from 10 to 100 meters (default is 10).
Kotlin
Java
1
Roam.updateCurrentLocation(DesiredAccuracy, accuracy)
Copied!
1
Roam.updateCurrentLocation(DesiredAccuracy, accuracy);
Copied!
This method should be used only if you need to update the current location of the device with better accuracy. Using this method consistently will consume more battery.
The higher the accuracy the longer the response time time. In some cases it could take up to 30 seconds depending on the GPS signal strength.
Parameter
Description
DesiredAccuracy
RoamTrackingMode.DesiredAccuracy.HIGH or RoamTrackingMode.DesiredAccuracy.MEDIUM or RoamTrackingMode.DesiredAccuracy.LOW

Logout

Logout from Cyprinus SDK, using logout() method.
NOTE : You need to reinitialize the SDK in case you want to login again.
Kotlin
Java
1
Roam.logout(object : RoamLogoutCallback {
2
override fun onSuccess(message: String) {
3
4
}
5
override fun onFailure(roamError: RoamError) {
6
// Access Error code and message here
7
// roamError.code
8
// roamError.message
9
}
10
})
Copied!
1
Roam.logout(new RoamLogoutCallback() {
2
@Override
3
public void onSuccess(String message) {
4
5
}
6
7
@Override
8
public void onFailure(RoamError roamError) {
9
// Access Error code and message here
10
// roamError.code;
11
// roamError.message;
12
}
13
});
Copied!

Notification Opened Handler

By using this method inside FirebaseMessagingService class, track the campaign impressions and counts.
Kotlin
Java
1
override fun onMessageReceived(RemoteMessage remoteMessage) {
2
super.onMessageReceived(remoteMessage)
3
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as
4
NotificationManager
5
....
6
intent.putExtra(Roam.EXTRA, Roam.notificationReceiveHandler(remoteMessage.getData()))
7
....
8
}
Copied!
1
@Override
2
public void onMessageReceived(RemoteMessage remoteMessage) {
3
super.onMessageReceived(remoteMessage);
4
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
5
...
6
intent.putExtra(Roam.EXTRA, Roam.notificationReceiveHandler(remoteMessage.getData()));
7
...
8
notificationManager.notify(NotificationID, builder.build());
9
}
Copied!
Kotlin
Java
1
override fun onCreate(savedInstanceState: Bundle?) {
2
super.onCreate(savedInstanceState)
3
....
4
Roam.notificationOpenedHandler(intent)
5
)
Copied!
1
@Override
2
protected void onCreate(Bundle savedInstanceState) {
3
super.onCreate(savedInstanceState);
4
...
5
Roam.notificationOpenedHandler(getIntent());
6
}
Copied!

Disable Battery Optimization (android 6+)

When running the SDK on Android 6 (and higher), it is recommended to ask the user to disable battery optimization for your application. This ensures that location tracking continues to work when the device is in Doze mode.
Moreover, on Android Pie, disabling battery optimization prevents Adaptive Battery from bucketing your app based on usage and restricting background processing, which can impact the detection quality of the SDK.
After explaining the benefits of disabling battery optimization, call the disableBatteryOptimization() method of the Cyprinus class.
Kotlin
Java
1
Roam.disableBatteryOptimization()
Copied!
1
Roam.disableBatteryOptimization();
Copied!
This will trigger a system dialog asking the user to allow disabling battery optimization for your app.

Check Battery Optimization

Kotlin
Java
1
Roam.isBatteryOptimizationEnabled()
Copied!
1
Roam.isBatteryOptimizationEnabled();
Copied!
Last modified 4mo ago