From e0820f106f42f071f95ccb70c8c879720491265b Mon Sep 17 00:00:00 2001 From: Dany Mestas <94061157+DanyPM@users.noreply.github.com> Date: Mon, 11 May 2026 16:26:58 +0200 Subject: [PATCH] AlarmClockReceiver: populate spec so notifications render on Xiaomi Previously sourceAppId, title, and body were left null and sourceName was the literal "ALARMCLOCKRECEIVER", causing Xiaomi watches to drop the alarm-fire notification (the watch falls back to Gadgetbridge's own package id which is not on the app allowlist, and the spec has nothing to display). Plumb the captured clock-app package (com.android.deskclock or com.google.android.deskclock) through sendAlarm so: - sourceAppId carries the real clock package - sourceName is the resolved application label (NotificationUtils.getApplicationLabel) - title = "Alarm" (R.string.menuitem_alarm) - body = current time formatted via DateFormat Strict improvement for all device families; Huami/ZeppOs previously also displayed the alarm with empty title/body. --- .../externalevents/AlarmClockReceiver.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmClockReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmClockReceiver.java index 8aca5630f0..36a559dfdd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmClockReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmClockReceiver.java @@ -20,16 +20,19 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.text.format.DateFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Date; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; +import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils; public class AlarmClockReceiver extends BroadcastReceiver { private static final Logger LOG = LoggerFactory.getLogger(AlarmClockReceiver.class); @@ -92,20 +95,24 @@ public class AlarmClockReceiver extends BroadcastReceiver { } if (ALARM_ALERT_ACTION.equals(action) || GOOGLE_CLOCK_ALARM_ALERT_ACTION.equals(action)) { - sendAlarm(context, true); + sendAlarm(context, true, packageName); } else if (ALARM_DONE_ACTION.equals(action) || GOOGLE_CLOCK_ALARM_DONE_ACTION.equals(action)) { - sendAlarm(context, false); + sendAlarm(context, false, packageName); } } - private synchronized void sendAlarm(Context context, boolean on) { + private synchronized void sendAlarm(Context context, boolean on, String packageName) { dismissLastAlarm(); if (on) { NotificationSpec notificationSpec = new NotificationSpec(); //TODO: can we attach a dismiss action to the notification and not use the notification ID explicitly? lastId = notificationSpec.getId(); notificationSpec.type = NotificationType.GENERIC_ALARM_CLOCK; - notificationSpec.sourceName = "ALARMCLOCKRECEIVER"; + notificationSpec.sourceAppId = packageName; + final String appLabel = NotificationUtils.getApplicationLabel(context, packageName); + notificationSpec.sourceName = appLabel != null ? appLabel : "Alarm Clock"; + notificationSpec.title = context.getString(R.string.menuitem_alarm); + notificationSpec.body = DateFormat.getTimeFormat(context).format(new Date()); notificationSpec.attachedActions = new ArrayList<>(); // DISMISS ALL action @@ -114,7 +121,6 @@ public class AlarmClockReceiver extends BroadcastReceiver { dismissAllAction.type = NotificationSpec.Action.TYPE_SYNTECTIC_DISMISS_ALL; notificationSpec.attachedActions.add(dismissAllAction); - // can we get the alarm title somehow? GBApplication.deviceService().onNotification(notificationSpec); } }