Skip to content

Utility Methods

Ekambaram edited this page Feb 22, 2021 · 5 revisions

Check location permission

Check whether your App has location permission.

GeoSpark.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.

GeoSpark.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.

GeoSpark.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.

GeoSpark.requestLocationPermission();  

Request Location Services

Android

Call this method to enable location services.

GeoSpark.requestLocationServices();

Request Background Location Permission

Android

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

GeoSpark.requestBackgroundLocationPermission();

Check Location Tracking

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

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

Current Location

Android

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

GeoSpark.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:

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

You can also remove event listeners:

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

Get the current location of the user in callback.

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

Parameter

Description

DesiredAccuracy

GeoSpark.DesiredAccuracy.HIGH or GeoSpark.DesiredAccuracy.MEDIUM or
GeoSpark.DesiredAccuracy.LOW

iOS

GeoSpark.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).

GeoSpark.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

GeoSpark.DesiredAccuracy.HIGH or GeoSpark.DesiredAccuracy.MEDIUM or
GeoSpark.DesiredAccuracy.LOW

iOS

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

Logout

Logout from GeoSpark SDK, using logout() method.

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

GeoSpark.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(GeoSpark.EXTRA, GeoSpark.notificationReceiveHandler(remoteMessage.getData()));
   ...
   notificationManager.notify(NotificationID, builder.build());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    GeoSpark.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 GeoSpark class.

GeoSpark.disableBatteryOptimization();

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

Check Battery Optimization

GeoSpark.isBatteryOptimizationEnabled();

Allow Mock Location

GeoSpark SDKs reject Mock Locations on the device by default.

GeoSpark.allowMockLocation(Boolean);

Parameter

Description

Boolean

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

Set Tracking in AppState

GeoSpark.setTrackingInAppState(STATE);

Parameter

Description

STATE

GeoSpark.AppState.FOREGROUND (or)

GeoSpark.AppState.BACKGROUND (or)

GeoSpark.AppState.ALWAYS_ON

Offline Location Tracking

GeoSpark.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

GeoSpark.enableAccuracyEngine();

for disable accuracy filter

 GeoSpark.disableAccuracyEngine();

Clone this wiki locally