Notification Support
kindly notification support in handover first provide the sdk with the fcm token using kindlysdk savenotificationtoken(token = "firebase token") when a push notification is received forward the notification to sdk using kindlysdk handlenotification(remotemessage = remotemessage) the sdk will double check if notification type is a kindly notification before handling it check if a notification is from kindly to determine if a notification should be handled by the kindly sdk or another notification provider, use the following helper method val iskindlynotification = kindlysdk iskindlynotification(remotemessage) this can be particularly useful when integrating with multiple push notification providers example usage override fun onmessagereceived(remotemessage remotemessage) { if (kindlysdk iskindlynotification(remotemessage)) { // handle with kindly sdk kindlysdk handlenotification(remotemessage) } else { // handle with another notification provider (e g , braze, mparticle) othernotificationprovider handlenotification(remotemessage) } } both calls work before start() process death and cold start fcm delivers kindly's data only messages to onmessagereceived even when the app process is not running in that process nothing has called kindlysdk start( ) yet; the sdk decrypts the push with the key it persisted when the chat registered the device and posts the banner on its own shouldhandlenotification is still asked when your interface is set in this process (after kill() ); a fresh process has none a device that never registered has no key and the push is dropped tapping the notification tapping a kindly banner opens the chat if the sdk is not started, the tap launches your launcher activity and the chat opens as soon as start() runs (a tap older than 60 seconds is dropped) set kindlysdk openchatonnotificationtap = false to only launch the app, and read the tap with kindlynotificationintent read(intent) in oncreate / onnewintent if you want to route it yourself when the sdk displays the notification kindly pushes are data only fcm messages with encrypted content; the sdk decrypts each one and posts a system notification with the decrypted title/body â except when the chat conversation is on screen the display rule is app state active screen sdk presents the banner? background any â
yes foreground chat conversation on screen â no (the user can already see the message) foreground settings, language, image preview, host app screens, etc â
yes heads up display in the foreground requires the kindly channel notification channel to remain at importance high (the sdk creates it that way, named "chat messages" in the system settings) and the user to have granted the post notifications runtime permission on android 13+ a push that cannot be shown for either reason is logged as permission denied or notifications disabled intercepting notifications ( shouldhandlenotification ) every kindly push that the sdk successfully decrypts while it is started is forwarded to the host app via the shouldhandlenotification(notification) method on kindlysdkinteraction â regardless of foreground/background state or which screen is on top before start() (process death) the sdk posts the banner without calling it use it to run side effects (analytics, logging, in app indicators) or to take over the presentation entirely with your own ui scenario result interface not set sdk presents the notification (subject to the display rule above) shouldhandlenotification returns true (default) sdk presents the notification (subject to the display rule above) shouldhandlenotification returns false sdk does not present anything â your app handles it the interface receives a externalnotification containing the decrypted fields plus the original remotemessage data map for any extra fields your backend attached data class externalnotification( val id string, // decrypted chat id val title string, // decrypted title val body string, // decrypted body val data map\<string, string>, // original remotemessage data ) implementation kindlysdk `interface` = object kindlysdkinteraction { override fun didpressbutton(chatbutton buttonchat, chatlog list\<messagechat>) { // handle button press if needed } override fun shouldhandlenotification(notification externalnotification) boolean { // always log every kindly notification, regardless of who presents it analytics track("kindly notification received", notification id) // example take over presentation when the app is in a custom in app inbox if (isshowingcustominbox) { custominbox add(notification) return false // sdk does not present its banner } return true // let the sdk present the banner } } notes the method has a default implementation that returns true , so you only need to override it if you want to observe or intercept notifications the callback fires for every successfully decrypted kindly push â it is not gated by the sdk's foreground/chat screen display rule use it for analytics that need to run even when the sdk is on screen the polarity matches shouldhandlelink returning true means "the sdk should handle this", returning false means "i'll handle it myself" returning false only suppresses the system notification â the underlying message has already been delivered to the chat session via the websocket / /latest endpoint, so it will appear in the chat history when the user opens it