Push messaging

Add Firebase Cloud Messaging integration
  1. Connect your application to the Firebase service
  2. Add Firebase Cloud Messaging dependency
  3. Use default Firebase Service
    1. Connect Woosmap Geofencing SDK to FireBase
    2. Define notification’s icon
  4. Implement your own Firebase Service

Push notifications are messages that pop up on mobile devices. App publishers can send them at any time; even if the recipients aren’t currently engaging with the app or using their devices.

Woosmap Geofencing SDK push messaging can be integrated with either Google Cloud Messaging (GCM) or Firebase Cloud Messaging (FCM). Although FCM is the latest push platform for Android, both GCM and FCM are fully supported. The following guide use FCM.

Connect your application to the Firebase service

A Firebase connexion is required by Woosmap’s library and is used to receive and display notifications.

To connect your application to Firebase follow this tutorial

If you see the following error:

Make sure to call FirebaseApp.initializeApp(Context) first 

It means that your application is not correctly connected to your Firebase project.

Add Firebase Cloud Messaging dependency

Add the dependency for Firebase Cloud Messaging in your module’s build.gradle.

dependencies {
    implementation 'com.google.firebase:firebase-messaging:17.3.0'
}

Use default Firebase Service

To ease the push messaging feature inside your app, Woosmap Geofencing SDK implement a default Firebase Service.

Connect Woosmap Geofencing SDK to FireBase

Update your AndroidManifest.xml file with the below code to connect Woosmap Geofencing SDK’s services to FireBase service.

<service android:name="com.webgeoservices.woosmap_mobile_sdk.WoosmapInstanceIDService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>
<service android:name="com.webgeoservices.woosmap_mobile_sdk.WoosmapMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

You can now set an Uri to an Activity of your application (example for the uri: woosmap://notif on the MainActivity) and you’re done.

<activity android:name=".MainActivity">
    ...
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="woosmap"
            android:host="notif" />
    </intent-filter>
</activity>
<meta-data android:name="woosmap_notification_defautl_uri" android:value="woosmap://notif" />

Define notification’s icon

To customize the small icon attached to the notifications, add the icon file in the directory res/drawable and update the meta-data in your AndroidManifest.xml file.

<meta-data
android:name="woosmap.messaging.default_notification_icon"
android:resource="@drawable/your_custom_icon_24dp" />

Implement your own Firebase Service

Please, refer to our Android Simple App hosted on GitHub.