fix(android): support static reminder notifications and ensure channel exists
Static reminders scheduled via scheduleDailyNotification() with isStaticReminder=true were being skipped because they don't have content in storage - title/body are in Intent extras. Fixed by: - DailyNotificationReceiver: Extract static reminder extras from Intent and pass to WorkManager as input data - DailyNotificationWorker: Check for static reminder flag in input data and create NotificationContent from input data instead of loading from storage - DailyNotificationWorker: Ensure notification channel exists before displaying (fixes "No Channel found" errors) Also updated prefetch timing from 5 minutes to 2 minutes before notification time in plugin code and web UI.
This commit is contained in:
@@ -68,7 +68,8 @@ public class DailyNotificationReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
// Enqueue work immediately - don't block receiver
|
||||
enqueueNotificationWork(context, notificationId);
|
||||
// Pass the full intent to extract static reminder extras
|
||||
enqueueNotificationWork(context, notificationId, intent);
|
||||
Log.d(TAG, "DN|RECEIVE_OK enqueued=" + notificationId);
|
||||
|
||||
} else if ("com.timesafari.daily.DISMISS".equals(action)) {
|
||||
@@ -99,17 +100,42 @@ public class DailyNotificationReceiver extends BroadcastReceiver {
|
||||
*
|
||||
* @param context Application context
|
||||
* @param notificationId ID of notification to process
|
||||
* @param intent Intent containing notification data (may include static reminder extras)
|
||||
*/
|
||||
private void enqueueNotificationWork(Context context, String notificationId) {
|
||||
private void enqueueNotificationWork(Context context, String notificationId, Intent intent) {
|
||||
try {
|
||||
// Create unique work name based on notification ID to prevent duplicates
|
||||
// WorkManager will automatically skip if work with this name already exists
|
||||
String workName = "display_" + notificationId;
|
||||
|
||||
Data inputData = new Data.Builder()
|
||||
// Extract static reminder extras from intent if present
|
||||
// Static reminders have title/body in Intent extras, not in storage
|
||||
boolean isStaticReminder = intent.getBooleanExtra("is_static_reminder", false);
|
||||
String title = intent.getStringExtra("title");
|
||||
String body = intent.getStringExtra("body");
|
||||
boolean sound = intent.getBooleanExtra("sound", true);
|
||||
boolean vibration = intent.getBooleanExtra("vibration", true);
|
||||
String priority = intent.getStringExtra("priority");
|
||||
if (priority == null) {
|
||||
priority = "normal";
|
||||
}
|
||||
|
||||
Data.Builder dataBuilder = new Data.Builder()
|
||||
.putString("notification_id", notificationId)
|
||||
.putString("action", "display")
|
||||
.build();
|
||||
.putBoolean("is_static_reminder", isStaticReminder);
|
||||
|
||||
// Add static reminder data if present
|
||||
if (isStaticReminder && title != null && body != null) {
|
||||
dataBuilder.putString("title", title)
|
||||
.putString("body", body)
|
||||
.putBoolean("sound", sound)
|
||||
.putBoolean("vibration", vibration)
|
||||
.putString("priority", priority);
|
||||
Log.d(TAG, "DN|WORK_ENQUEUE static_reminder id=" + notificationId);
|
||||
}
|
||||
|
||||
Data inputData = dataBuilder.build();
|
||||
|
||||
OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(DailyNotificationWorker.class)
|
||||
.setInputData(inputData)
|
||||
|
||||
Reference in New Issue
Block a user