Android Wear startForeground not displaying notification

Viewed 20

I am writing an Android Wear app that uses a foreground service. I have verified that the foreground service wokrs, and the code inside the service executes as needed (SensorEventListener) and I even use intents to display information in the UI.

However, the notification for the service is not posting in the list of notifications. I use a Galaxy Watch4 for testing.

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    broadcaster = LocalBroadcastManager.getInstance(this)

    val notificationIntent = Intent(this, MainActivity::class.java)
    val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, FLAG_IMMUTABLE)

    val notificationChannel = NotificationChannel(foregroundChannelId, "Foreground Service", NotificationManager.IMPORTANCE_HIGH)

    notificationChannel.lightColor = Color.BLUE
    notificationChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC

    val service = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    service.createNotificationChannel(notificationChannel)

    val notification = NotificationCompat.Builder(this, foregroundChannelId).setOngoing(true)
            .setContentTitle("Monitoring sensors").setContentText("app_name is actively monitoring your biosensors.")
            .setContentIntent(pendingIntent).setCategory(Notification.CATEGORY_SERVICE).setSmallIcon(R.mipmap.ic_launcher).build()

    startForeground(1, notification)

    prepareSensors()

    return START_NOT_STICKY
}

There is no sticky notification in the notification panel.

I've tried removing the .setOngoing.

0 Answers
Related