0

在 android 8 及更高版本的设备上启动前台服务时,我一直面临通知徽章的问题。我什至尝试使用通知通道对象禁用徽章,但问题仍然存在。我们正在使用下面的代码块。

@RequiresApi(api = Build.VERSION_CODES.O)
private void startMyOwnForeground() {
    Log.d("ForegroundService", "inside startmyownforeground");
    String NOTIFICATION_CHANNEL_ID = "custom_ID";
    String channelName = "NOTIFICATION CHANNEL";
    NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    assert manager != null;
    chan.setShowBadge(false);
     Log.d("Notification::", "From Foreground Service.");
    manager.createNotificationChannel(chan);

    Notification.Builder notificationBuilder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID);
    Log.d("Foregroundservice","log for cheking notif title");
    Notification notification = notificationBuilder.setOngoing(true)
            .setSmallIcon(getIconResId())
            .setContentTitle(NOTIFICATION_TEXT)
            .setContentText(NOTIFICATION_TEXT)
            .setTicker(NOTIFICATION_TEXT)
            .build();
    startForeground(NOTIFICATION_ID, notification);
    Log.d("ForegroundService","end of startMyOwnForeground");
}
4

0 回答 0