androidandroid-notificationswear-osandroid-wear-notification

Wear OS: notifications won't show


I am developing a stand alone app on Wear OS (Android 8+) and I have issues with notifications.

I am running a Foreground Service, with an on-going notification. That on-going notification works very well and has no feature from the Wear OS (so the code can work on standalone Android).

However, whenever I want to display other notifications, it is impossible.

No error message, nothing: my notifications are not displayed. I made sure to create separate channels and to have them enabled (via the settings).

Here is my code, running in the Looper.mainLooper() via a Handler.

final Notification notification = new NotificationCompat.Builder(MonitorService.this, LOGS_CHANNEL_ID)
                        .setSmallIcon(R.drawable.ic_backup_logs) // vector (doesn't work with png as well)
                        .setContentTitle(getString(R.string.monitor_service_notification_log_file_backed_up_process))
                        .setContentText("test")
                        .setPriority(NotificationCompat.PRIORITY_HIGH)
                        .build();

notificationManagerCompat.notify(LOGS_ID, notification); // unique final static id

Am I missing something here ?

Thanks for the help !


Solution

  • Use this code

    Notification.Builder b = new Notification.Builder(ctx);
    
        //FIX android O bug Notification add setChannelId("shipnow-message")
        NotificationChannel mChannel = null;
        b.setSmallIcon(R.drawable.ic_backup_logs) // vector (doesn't work with png as well)
                        .setContentTitle(getString(R.string.monitor_service_notification_log_file_backed_up_process))
                        .setContentText("test")
                        .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            mChannel = new NotificationChannel("your-channel", "yourSubjectName",NotificationManager.IMPORTANCE_HIGH);
            b.setChannelId("your-channel");
        }
    
        NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            notificationManager.createNotificationChannel(mChannel);
        }
        notificationManager.notify(id, b.build());