I searched about it but I can't figure this out!!
There are a few answers but they are not working in Android 8.0 or above.
I saw this feature in Alibaba and WhatsApp!!
Help if you can! This can help others too.
My Codes:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(getString(R.string.default_notification_channel_id), remoteMessage.getData().get("title"), NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true);
channel.setLightColor(0xff0000);
channel.shouldShowLights();
channel.canShowBadge();
notificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "0")
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_notification))
.setContentTitle(remoteMessage.getData().get("title"))
.setContentText(remoteMessage.getData().get("message"))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setPriority(NotificationCompat.PRIORITY_MAX)
.setVibrate(new long[] {0, 1000, 200,1000 })
.setChannelId(getString(R.string.default_notification_channel_id))
.setLights(Color.RED, 100 , 100)
.setAutoCancel(true);
if (notificationManager != null) {
Notification notification = notificationBuilder.build();
notification.ledARGB = 0xFFff0000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notificationManager.notify(new Random().nextInt(60000), notification);
}
enable lights in the channel
https://developer.android.com/reference/android/app/NotificationChannel.html#enableLights(boolean)
Deprecated codes so i should remove these:
notification.ledARGB = 0xFFff0000;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
And replaced IMPORTANCE_DEFAULT to IMPORTANCE_MAX like below
NotificationChannel channel = new NotificationChannel(getString(R.string.default_notification_channel_id),
remoteMessage.getData().get("title"), NotificationManager.IMPORTANCE_MAX);
And like @tyzj's answer and @dharms comment i added this with alpha color:
channel.enableLights(true);
channel.setLightColor(0xffff0000)
And changed
.setLights(Color.RED, 100 , 100)
To
.setLights(0xffff0000, 1000 , 1000)
User contributions licensed under CC BY-SA 3.0