首页 文章

穿OS:通知不会显示

提问于
浏览
0

我正在开发Wear OS(Android 8)上的独立应用程序,我遇到了通知问题 .

我正在运行 Foreground Service ,正在进行通知 . 正在进行的通知非常有效,并且没有Wear OS的功能(因此代码可以在独立的Android上运行) .

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

没有错误消息,没有:我的通知没有显示 . 我确保创建单独的 Channels 并启用它们(通过设置) .

这是我的代码,通过 HandlerLooper.mainLooper() 中运行 .

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

我在这里错过了什么吗?

谢谢您的帮助 !

1 回答

  • 0

    使用此代码

    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());
    

相关问题