Проблема с уведомлением службы переднего плана

#android #notifications #foreground-service

Вопрос:

У меня есть служба переднего плана, и я создаю уведомления через нее. setColor работает не для всех устройств, даже если они работают под управлением одной и той же ОС.

Кто-нибудь видел эту проблему раньше? Есть ли какие-либо намеки на то, как с этим бороться?

 @Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String input = intent.getStringExtra("inputExtra");
    createNotificationChannel();

    Spannable spannable = new SpannableString(input);
    spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, input.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.addLine(spannable);

    Intent fullScreenIntent = CallStateObserver.launchCallScreenIntent(getApplicationContext(), "", null, null);
    PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(getApplicationContext(), (int) System.currentTimeMillis(), fullScreenIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setContentTitle(Build.VERSION.SDK_INT == 23 ? getApplicationContext().getResources().getString(R.string.app_name):"")
            .setContentText(input)
            .setGroup("false")
            .setPriority(Notification.PRIORITY_MAX)
            .setSmallIcon(android.R.drawable.ic_menu_call)
            .setFullScreenIntent(fullScreenPendingIntent, true)
            .setColorized(true)
            .setUsesChronometer(true)
            .setStyle(inboxStyle)
            .setColor(ContextCompat.getColor(getApplicationContext(), R.color.accent))
            .build();
    startForeground(1, notification);
    return START_STICKY;
}
 

Комментарии:

1. можете ли вы поделиться своим кодом уведомления?

2. @Napster только что добавил код