Notification LED not turning on

0

I tried almost every fix posted here but this code won't turn on Notification LED at all.

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

I'm sending notification from Firebase and everything works perfectly fine except the LED lights. LED notification from other apps work fine.

java
android
firebase-cloud-messaging
android-notifications
asked on Stack Overflow Oct 5, 2019 by Saad Waseem • edited Oct 5, 2019 by Frank van Puffelen

1 Answer

0

You can't change channel color notification after Oreo/API 26.

developer.android.com

answered on Stack Overflow Oct 5, 2019 by RKRK

User contributions licensed under CC BY-SA 3.0