The following code sets a lock screen messagge containing an alarm clock icon and the next alarm time as text message. If no alarm is set at all the lock screen message will be deleted.
private void RefreshNotificationForLockScreen(Context context, AlarmInfo alarmInfo)
{
int myNotificationId = 18;
if (alarmInfo.alarmTime.isEmpty())
{
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.cancel(myNotificationId);
}
else
{
Notification notification = new Notification.Builder(context)
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentTitle(alarmInfo.alarmTime)
.setContentText("Nächster Alarm in " + alarmInfo.durationUntilAlarm)
.setSmallIcon(R.drawable.alarm_clock)
.setOngoing(true)
.setAutoCancel(false).build();
notification.visibility = NotificationCompat.VISIBILITY_PUBLIC;
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
notificationManager.notify(myNotificationId, notification);
}
}