Skip to content

Utility Methods

Ekambaram edited this page Mar 17, 2021 · 2 revisions

Check location permission

Check whether your App has location permission.

Roam.checkLocationPermission( status => {
// do something with status
}); 

status will be a string, one of:

  • GRANTED

  • DENIED

Check location services

Android

Check whether the device has location services enabled.

Roam.checkLocationServices( status => {
// do something with status
}); 

status will be a string, one of:

  • ENABLED

  • DISABLED

Check Background Location Permission

Android

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.

Roam.checkBackgroundLocationPermission( status => {
// do something with status
});

status will be a string, one of:

  • GRANTED

  • DENIED

Request Location Permissions

Call this method to request the user to enable location permissions.

Roam.requestLocationPermission();  

Request Location Services

Android

Call this method to enable location services.

Roam.requestLocationServices();

Request Background Location Permission

Android

Call this method to request the user to enable background location permissions.

Roam.requestBackgroundLocationPermission();

Check Location Tracking

Check whether location tracking is started or not. This method returns a boolean value.

Roam.isLocationTracking( status => {
    // do something with status
});

Current Location

Android

Get the current location of the user. You can set the accuracy from 10 to 100 meters (default is 10).

Roam.getCurrentLocationListener(accuracy);

You only need to call these method once, as these settings will be persisted across App sessions.

To listen for location updates, you can add event listeners:

Roam.startListener('location', (result) => {   
 // do something with location
});

You can also remove event listeners:

//Stop location updates
Roam.stopListener('location'); 

Get the current location of the user in callback.

Roam.getCurrentLocation(DesiredAccuracy, accuracy, success => { 
  // do something on success    
}, error => {
 // do something on error
});

Parameter

Description

DesiredAccuracy

Roam.DesiredAccuracy.HIGH or Roam.DesiredAccuracy.MEDIUM or
Roam.DesiredAccuracy.LOW

iOS

Roam.updateCurrentLocationIos(accuracy);

Update Current Location

Android

Using the updateCurrentLocation method, you can update the user's current location, you can set the accuracy from 5 to 100 meters (default is 10).

Roam.updateCurrentLocation(DesiredAccuracy, accuracy);

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

Roam.DesiredAccuracy.HIGH or Roam.DesiredAccuracy.MEDIUM or
Roam.DesiredAccuracy.LOW

iOS

Roam.getCurrentLocationIos(accuracy, success => { 
  // do something on success    
}, error => {
 // do something on error
});    

Logout

Logout from Roam SDK, using logout() method.

NOTE : You need to reinitialize the SDK in case you want to login again.

Roam.logout( success => {
// do something on success
}, error => {
// do something on error
});

Notification Opened Handler

By using this method inside FirebaseMessagingService class, track the campaign impressions and counts.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
   super.onMessageReceived(remoteMessage);
   NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   ...
   intent.putExtra(Roam.EXTRA, Roam.notificationReceiveHandler(remoteMessage.getData()));
   ...
   notificationManager.notify(NotificationID, builder.build());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    Roam.notificationOpenedHandler(getIntent());
}

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 Roam class.

Roam.disableBatteryOptimization();

This will trigger a system dialog asking the user to allow disabling battery optimization for your app.

Check Battery Optimization

Roam.isBatteryOptimizationEnabled();

Allow Mock Location

Roam SDKs reject Mock Locations on the device by default.

Roam.allowMockLocation(Boolean);

Parameter

Description

Boolean

false (default) -- Mock location disabled.
true -- Mock location enabled

Set Tracking in AppState

Roam.setTrackingInAppState(STATE);

Parameter

Description

STATE

Roam.AppState.FOREGROUND (or)

Roam.AppState.BACKGROUND (or)

Roam.AppState.ALWAYS_ON

Offline Location Tracking

Roam.offlineLocationTracking(Boolean);

Parameter

Description

Boolean

true (default) -- Offline location enabled.
false -- Offline location disabled.

Accuracy filter

For enable accuracy filter for passive , active and reactive tracking

Roam.enableAccuracyEngine();

for disable accuracy filter

 Roam.disableAccuracyEngine();