GeoSync¶
The GeoSync feature allows you to request an immediate synchronisation of all your installed devices after making changes to the geofence configuration.
Before you can use GeoSync you first need to register a Firebase project in the Firebase Console.
Once your project is registered you can get the server key from the Cloud Messaging tab of the Project Settings pane on the Firebase console -


Enter the server key into the GeoMoby Application Settings.

Add Firebase to your Android project -
If you’re using the latest version of Android Studio (version 2.2 or later), we recommend using the Firebase Assistant to connect your app to Firebase. The Firebase Assistant can connect your existing project or create a new one for you and automatically install any necessary dependencies.
Click Tools > Firebase to open the Assistant window.
Click to expand the Cloud Messaging feature, then click the provided tutorial link (Set up Firebase Cloud Messaging).
Follow the tutorial steps to add Firebase and enable Cloud Messaging.
If you’re using an older version of Android Studio or have a more complex project configuration, you can Manually add Firebase to your App.
Add a service that extends FirebaseInstanceIdService. This will be used to retrieve the InstanceId which uniquely represents this device. In this service implement override method onTokenRefresh(). This will be triggered when a new token is generated -
@Override
public void onNewToken(@NotNull String token) {
super.onNewToken(token);
// Update firebase token
GeoMoby.updateFirebaseId(token);
}
Add a service that extends FirebaseMessagingService. This will be used to handle incoming push notifications. In this service implement override method onMessageReceived(). This will be triggered by a push notification to the device -
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getFrom().equals("/topics/GeomobySync")) {
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
String messageType = remoteMessage.getData().get("MessageType");
if (messageType.equals("GeomobySyncRequest")) {
// Update fence list
GeoMobyManager.getInstance().updateFences();
}
}
}
}
Add service registrations to the Android manifest for the Instance ID and Messaging listener services (set service names to the names you use) -
<service
android:name=".MyInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name=".MyFcmListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Add the following code to your MainActivity onCreate method to subscribe to the GeomobySync topic -
FirebaseMessaging.getInstance().subscribeToTopic("GeomobySync");