Samsung watch 4 not show notification from FCM, Ca...
# compose-wear
l
Samsung watch 4 not show notification from FCM, Can anyone who has handled this give me a guide? Data have return: Notification: title and body. But notification isn’t show when wear is background or foreground?
k
Cc @Garan Jenkin if you have any immediate suggestions. Otherwise I'd suggest to file an issue at the public issue tracker for further investigation.
l
yup, i log data from FCM, but not show on notification on device. Enabled setting show notiifcation
Copy code
class MyFirebaseMessagingService : FirebaseMessagingService() {
    private val notificationManager by lazy { NotificationManagerCompat.from(applicationContext) }
    override fun onNewToken(token: String) {
        super.onNewToken(token)
    }

    override fun onMessageReceived(message: RemoteMessage) {
        super.onMessageReceived(message)
        sendNotification(message)
    }

    private fun sendNotification(message: RemoteMessage) {
        val intent = Intent(this, MainActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        val pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
        val pendingIntent = PendingIntent.getActivity(
            this, NOTIFICATION_ID/* Request code */, intent,
            pendingIntentFlags
        )
        Log.e("AAAAAAAAAAAAA", "${message.notification?.title}---- ${message.notification?.body}")
        if (ActivityCompat.checkSelfPermission(
                this,
                Manifest.permission.POST_NOTIFICATIONS
            ) != PackageManager.PERMISSION_GRANTED
        ) {
            Log.e("AAAAAAAAAAAAA", "GRANT PERMISSION NOTIFICATION")
            return
        }
        notificationManager.notify(
            NOTIFICATION_ID, createNotification(
                message.notification?.title, message.notification?.body,
                addBuilder = {
                    setContentIntent(
                        pendingIntent
                    )
                }
            )
        )
    }

    private fun createNotificationChannelIfAboveAndroidO() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel(
                applicationContext.getString(R.string.notification_message_channel_id),
                applicationContext.getString(R.string.notification_message_channel_name),
                NotificationManager.IMPORTANCE_HIGH
            ).apply {
                description = applicationContext.getString(
                    R.string.notification_message_channel_description
                )
            }.let { notificationManager.createNotificationChannel(it) }
        }
    }

    private fun createNotification(
        title: String?,
        content: String?,
        addBuilder: NotificationCompat.Builder.() -> NotificationCompat.Builder,
    ): Notification {
        createNotificationChannelIfAboveAndroidO()
        return NotificationCompat.Builder(
            applicationContext,
            applicationContext.getString(R.string.notification_message_channel_id)
        ).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_app_notification)
            .setColor(applicationContext.resources.getColor(R.color.colorPrimary))
            .setContentText(content)
            .setContentTitle(title)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .extend(
                NotificationCompat.WearableExtender()
                    .setBridgeTag("tagOne")
            )
            .run(addBuilder)
            .build()
    }

    companion object {
        const val NOTIFICATION_ID = 100
    }
}
config mainifest:
it worked, thank you