stream-chat-android icon indicating copy to clipboard operation
stream-chat-android copied to clipboard

Notifications don't appear when app is killed

Open JayMehta97 opened this issue 3 years ago • 5 comments

Describe the bug Chat notifications are not shown when app is killed and are only shown when app is in foreground or background.

We recently upgraded from 4.28.2 to 5.11.0. In 4.28.2, notifications were shown correctly in all scenarios but after we upgraded the SDK to 5.11.0 we have started facing this issue.

In 4.28.2 the app shows 2 notifications, one with correct data and another with Loading notification data text which would disappear in few seconds. In 5.11.0 its the same behaviour of 2 notifs when app is in foreground or background but when app is killed then the app shows only 1 notification with Loading notification data text which would disappear in few seconds.

Also raising support ticket with app, channel and user info.

SDK version

  • 5.11.0

To Reproduce Steps to reproduce the behavior:

  1. Kill the app in device A
  2. Send a message from device B to device A
  3. Device A won't show notification with correct data

Expected behavior User should receive notification with correct data

Device:

  • Vendor and model: Vivo V2033
  • Android version: 11

Screenshots

When app is in foreground or background. The Loading notification data notification will disappear in few seconds:- Screenshot 2022-09-28 at 4 44 29 PM

When app is killed. The Loading notification data notification will disappear in few seconds:- Screenshot 2022-09-28 at 4 45 03 PM

JayMehta97 avatar Sep 28 '22 11:09 JayMehta97

Hello @JayMehta97 Could you show us how and where you are initializing our SDK? Do you have any logs about the error? Are you using any custom NotificationHandler?

The StreamChat SDK should be initialized on the application to have a proper behavior as we recommend on our docs. It seems it is not initialized at the moment we are handling the notification

JcMinarro avatar Sep 28 '22 13:09 JcMinarro

Hey @JcMinarro,

We are initializing the SDK as recommended in the docs inside onCreate method of the app.

We do you use custom notification handler. We don't directly use stream chat inside our app, we have created a chat module which uses stream and then we import that chat module in our main app.

Initialising our module app from main app:

override fun onCreate() {
        super.onCreate()
        ...
        CustomChatModule.init(
            apiKey = STREAM_CHAT_KEY,
            this,
            notificationIcon = R.drawable.ic_logo
        ) { messageId: String, channelType: String, channelId: String ->
            Intent(this, SomeActivity::class.java).apply {
                flags = FLAG_ACTIVITY_NEW_TASK
                val url =
                    AppConstants.DeepLink.Path.chatMessageUrl + messageId + "/" + channelType + "/" + channelId
                data = Uri.parse(url)
            }
        }
       ...
}

Initialising stream chat from chat module:

fun init(
    apiKey: String,
    context: Context,
    @DrawableRes notificationIcon: Int?,
    getNotificationHandlerIntent: (messageId: String, channelType: String, channelId: String) -> Intent
) {
    val notificationConfig = NotificationConfig(
        pushDeviceGenerators = listOf(
            FirebasePushDeviceGenerator()
        )
    )

    val notificationHandler = CustomNotificationHandler(
        context = context,
        getNotificationHandlerIntent = { messageId: String, channelType: String, channelId: String ->
            getNotificationHandlerIntent(messageId, channelType, channelId)
        },
        notificationIcon = notificationIcon
    )

    val offlinePluginFactory = StreamOfflinePluginFactory(
        config = Config(
            backgroundSyncEnabled = true,
            userPresence = true,
            persistenceEnabled = true,
            uploadAttachmentsNetworkType = UploadAttachmentsNetworkType.NOT_ROAMING,
        ),
        appContext = context,
    )

    ChatClient
        .Builder(apiKey = apiKey, appContext = context)
        .withPlugin(offlinePluginFactory)
        .notifications(notificationConfig, notificationHandler)
        .build()

    log(message = "Created chat client")
    CustomChatConfiguration.setup(context)
}

Custom notification handler: CustomNotificationHandler.txt

Let me know if any more details are needed. Most of the code inside custom notification handler is taken from stream's notification handler but of earlier version, not sure if we need to update it as we have updated streams SDK version.

Thanks.

JayMehta97 avatar Sep 29 '22 08:09 JayMehta97

Hey @JcMinarro,

Any update on this?

JayMehta97 avatar Oct 03 '22 12:10 JayMehta97

Hello @JayMehta97 Sorry for the delay. I have been reviewing your implementation and it looks good. I have been trying to replicate this issue on our side but I couldn't replicate it. Could you verify that when the app is killed and a Push Notification is received (You said the "loading notification data" notification is shown, it should only be shown when a PN is received from our server and we are fetching the message data) our Chat SDK is initialized by the code you show us on your previous comment? On the other hand, I would like to know if you are manually disconnecting the user by calling ChatClient.disconnect(), and on that case if you are passing true/false on the flushPersistence arguments. If you pass true as argument, the userCredentials will be deleted, and on that case PN can be dropped.

JcMinarro avatar Oct 03 '22 16:10 JcMinarro

Hey @JcMinarro,

We are manually disconnecting the user but with argument as false and still it has the same behaviour.

This issue is a blocker for our next priority release. Can we connect over a quick call so that we can resolve this?

Thanks.

JayMehta97 avatar Oct 10 '22 07:10 JayMehta97

Closing as it was merged and released.

filbabic avatar Nov 28 '22 07:11 filbabic