3

I have problems with receiving the notifications (made by the wear application) on my samsung watch 4 wear os 3.5. My code was working until the recent update; which basically started a Foreground Service with a notification. The service is running, but the notification is not visible. I have no errors. Other than this, normal notifications are not showing neither, made BroadcastReceiver (alarms in every 15 min).

I made a dummy app, which has only one button and generates a notification (nothing special), but it does (or actually does not) the same thing: I can not see the notification.

Steps:

  • create a notification channel
  • toast a text
  • create a notification

Code:

class MainActivity : Activity() {

    private lateinit var binding: ActivityMainBinding
    val CHANNEL_ID = "test1234"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Create the NotificationChannel
            val name = getString(R.string.channel_name)
            val descriptionText = getString(R.string.channel_description)
            val importance = NotificationManager.IMPORTANCE_HIGH

            val mChannel = NotificationChannel(CHANNEL_ID, name, importance)
            mChannel.description = descriptionText
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
            notificationManager.createNotificationChannel(mChannel)
        }

        // get reference to button
        val btn_click_me = findViewById<Button>(R.id.btn_click_me)

        // set on-click listener
        btn_click_me.setOnClickListener {
            Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show()

            var builder = Notification.Builder(this, CHANNEL_ID)
                .setSmallIcon(R.drawable.logo)
                .setContentTitle("Test title")
                .setContentText("Test content")
                .setPriority(Notification.PRIORITY_DEFAULT)

            val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
            notificationManager.notify(1, builder.build())
        }
    }
}

Can you see anything stupid in my code? The CHANNEL_ID is the same both when creating the channel and creating the builder. The Notification has an ID > 0 (as I saw, 0 as the ID is not working); I also tried with other IDs as well.

I saw there are a "huge" improvement in the notifications with the latest SW upgrade (which can not been undone ........), but it is not working for me at all.

Is there anyone who had the same problem or sees the problem in my dummy code?

Kind regards,

BalintT86
  • 31
  • 1
  • Is it maybe related to the fact notifications are disabled by default on Android API 33? https://developer.android.com/develop/ui/views/notifications/notification-permission#new-apps I tried looking to see what Wear OS 3.5 is based on, but uh... Google really doesn't like keeping their documentation up to date huh – cactustictacs Nov 16 '22 at 19:32
  • 1
    There are also changes in Android 12 (31) where a foreground service notification doesn't show for 10 seconds by default (to avoid a situation where a service pops up and disappears quickly) - some info here: https://developer.android.com/guide/components/foreground-services . Also the Wear page on notifications recommends using `NotificationCompat` instead of the built-in stuff - it shouldn't matter for this, but I thought I'd mention it just in case. Definitely check the permissions though - if you look at your app's notification settings, check that the on switch is actually toggleable – cactustictacs Nov 16 '22 at 19:41
  • Thanks for your comment. OS3.5 is Android 11 as I know. The foreground service is running, because relaunching the app checks if it is there or not (to not start it twice). The notification channel is available (debugged it). There is no error in Logcat. Actually yesterday evening it was working for some time, than today it brooke again. It turned out, that for some reason the notifications were disabled ON THE PHONE. I was not even touching it......... – BalintT86 Nov 17 '22 at 12:54
  • I was thinking more that since Wear OS is *based* on Android, but not exactly, that maybe this new release had rolled in similar notification behaviour to kinda keep parity with the current Android experience, if you get me (I don't know anything about Wear OS if you couldn't tell, I'm just throwing some ideas out there!) The current behaviour with notifications in Android 13, if you haven't explicitly added the permission (and been granted it) is that they just don't appear, so I'm wondering if they're emulating that somehow? I couldn't find any official info about Wear OS 3.5 though! – cactustictacs Nov 17 '22 at 16:02
  • Also it might be worth seeing if any of the stuff on the bug tracker looks like it might apply to you: https://issuetracker.google.com/issues?q=wear%20os%20notifications Hope you get it sorted out! – cactustictacs Nov 17 '22 at 16:03
  • Have you found solution for this? – Yupi Jan 25 '23 at 13:37
  • Yes, you need to manually enable the notifications for you application from the phone. Then it is working fine. – BalintT86 Jan 26 '23 at 14:03

1 Answers1

0

I had to manually go to the SamsungWear app on my mobile , find the notifications screen in it's settings and enable notification for my app from over there.

Not sure if there is a convenient way to this ( Using intents or permission Pop-Up ). The documentation doesn't mention any such thing.

Divesh
  • 112
  • 1
  • 6