Notifications
5 min
the appstorys sdk ships its own firebasemessagingservice, click handler, and notification rendering the only thing your app needs to do is forward the firebase cloud messaging (fcm) token to appstorys call appstorys setfirebasetoken(token) whenever you have an fcm token appstorys setfirebasetoken(token) this registers the device with appstorys outreach backend so push campaigns can be delivered when to call it on every new token from firebase fcm rotates tokens periodically — after app reinstall, data clear, long inactivity, or at firebase's discretion your firebasemessagingservice will be notified via onnewtoken forward it using the same appstorys setfirebasetoken(token) function if you use another push provider, send the data to appstorys as well override fun onmessagereceived(remotemessage remotemessage) { super onmessagereceived(remotemessage) val handledbyappstorys = appstorysmessagingservice handlemessage(this, remotemessage) if (handledbyappstorys) return // any other provider / their own default handling } override fun onnewtoken(token string) { super onnewtoken(token) appstorysmessagingservice handlenewtoken(this, token) // their own backend, other sdks } managing push opt in/opt out if your app has its own notification preference toggle (separate from the os permission), use appstorys subscribenotifications() appstorys unsubscribenotifications() call unsubscribenotifications() when the user turns your in app push toggle off, and subscribenotifications() when they turn it back on this only affects whether appstorys sends campaigns to the user server side — it doesn't remove the fcm token os level permission changes (user denies/allows notifications from system settings) are already detected and synced automatically — you don't need to call this yourself for that case requires the sdk to already be initialized and userid to be set enabling heads up (pop up) notifications by default, appstorys notifications may appear silently in the notification tray rather than popping up as a heads up banner to make them pop up, create the notification channel with high importance before the sdk does, by adding the following to your application oncreate() if (build version sdk int >= build version codes o) { val channel = notificationchannel( "appstorys outreach", "outreach", notificationmanager importance high ) val mgr = getsystemservice(notificationmanager class java) mgr createnotificationchannel(channel) }