Starting and stopping services¶
Implementing the GeoMoby builder¶
In your onCreate() method in your main activity, implement the GeoMoby builder:
/*************************
* Android Java
*************************/
GeoMoby mGeoMoby = new GeoMoby.Builder(getApplicationContext(), "12345678", mServiceCallback)
.setDevMode(true)
// enables logs
.setOfflineMode(true) // sets to true if your projet requires to work in poor connectivity areas. This mode will save bandwitdh and battery but the SDK won't be able to use online geomodules such as weather, traffic...
.setUUID("12345678-1234-1234-1234-bc5b71e0893e")
// sets beacons UUID filtering
.setSilenceWindow(23,5) // sets time from start hour(0-23) to stop hour(0-23) window, when action message callback shouldn’t be called.
.setTags(tags) // tags are profile attributes that you can pass onto the GeoMoby server for segmentation
.build();
// build geomoby object with pre-defined parameters
/*************************
* Kotlin
*************************/
init {
GeoMoby.Builder(App.instance.applicationContext, "12345678", mServiceCallback)
.setDevMode(true)
.setOfflineMode(true)
.setUUID("12345678-1234-1234-1234-bc5b71e0893e")
.setSilenceWindow(0, 1)
.build()
}
Note: “12345678” is your appKey and can be found on the GeoMoby Application Settings page. Note: Offline mode is available from SDK v2.8 only
Note: GeoMoby.Builder() returns the GeoMoby object. You can access the GeoMoby object using GeoMoby.getInstance() or via your own GeoMoby object.
Implementing Callback Services¶
/*************************
* Android Java
*************************/
// Service actions callback
GeomobyServiceCallback mServiceCallback = new GeomobyServiceCallback(){
@Override
public void onStarted() {Log.d("Geomoby_Test", "Service started!");}
@Override
public void onStopped() {Log.d("Geomoby_Test", "Service stopped!");}
@Override
public void onError(GeomobyError error) {Log.d("Geomoby_Test", "Error - " + error.getMessage() + "!");}
};
/*************************
* Kotlin
*************************/
object GeomobyManager : GeomobyServiceCallback {
override fun onStarted() {
Log.d(TAG, "Service started!")
}
override fun onError(geomobyError: GeomobyError?) {
Log.d(TAG, "Error - ${geomobyError?.message.toString()}!")
}
override fun onStopped() {
Log.d(TAG, "Service stopped!")
}
}
The service callback contains 3 main methods:
onStarted() - when geomoby service has started
onStopped() - when geomoby service has stopped
onError() - when geomoby service has faced some errors
Geomoby Error class contains 2 methods:
getMessage() - returns the detail message string of this error
getCode() - error type. The error types that can be returned are -
public enum GeomobyErrorCode{
INTERNET_DISABLED,
GPS_DISABLED,
BLE_DISABLED
}
Start the Geomoby service¶
GeoMoby.start();
Stop the Geomoby service¶
GeoMoby.stop();