Светодиод уведомления не включается - PullRequest
0 голосов
/ 05 октября 2019

Я перепробовал почти все исправления, опубликованные здесь, но этот код вообще не включал индикатор уведомлений.

public void onMessageReceived(RemoteMessage remoteMessage) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String channelId = getString(R.string.defaultChannelId);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this,channelId)
                    .setLights(Color.RED,200,1000)
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setAutoCancel(true)
                    .setDefaults(NotificationCompat.DEFAULT_ALL)
                    .setContentTitle(remoteMessage.getNotification().getTitle())
                    .setContentText(remoteMessage.getNotification().getBody())
                    .setSmallIcon(R.drawable.omega_icon)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

    Notification notification = notificationBuilder.build();
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(channelId,
                "Channel human readable title",
                NotificationManager.IMPORTANCE_DEFAULT);
        channel.enableLights(true);
        channel.setLightColor(0xFFFFFFFF);
        notificationManager.createNotificationChannel(channel);
    }
    notificationManager.notify(1, notification);
}

Я отправляю уведомление от Firebase, и все отлично работает, кроме светодиодов. Светодиодные уведомления из других приложений работают нормально.

1 Ответ

0 голосов
/ 05 октября 2019

Вы не можете изменить цвет уведомления канала после Oreo / API 26.

developer.android.com

...