Android:如何知道何时触发警报

Android: how to know when an alarm is triggered

我正在尝试按照这些步骤管理警报,我需要帮助!

使用 SQLite table 等来正确跟踪警报,以及创建、计划和触发的时间戳。

这里是关于 Whosebug 的回答:AlarmMenager Checking if alarm already fired

所以我创建了在特定日期触发的闹钟,这确实有效。我在设置警报和其他详细信息时插入 SQLite。

但我的问题是我需要在警报准确触发时更新 SQLite 中的 Table。更新“triggered_at”列。

这是我下面触发警报的代码!

        //Alarm Manager Set

        alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, ReminderAlarmReceiver.class);
        alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);


        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_WEEK, 5); // 5 is Thursday
        calendar.set(Calendar.HOUR_OF_DAY, 4); // 4 is 4:00AM HOUR
        calendar.set(Calendar.MINUTE, 48); // 48 is 48 minutes
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);


        /* Insert SQLite data */
        db.execSQL("CREATE TABLE IF NOT EXISTS MyTable (Name VARCHAR, Repeating INT, time FLOAT, alarm_set_at INT, triggered_at INT)");

        //Get current time and other details and replace the static values
        db.execSQL("INSERT INTO MyTable VALUES ('Brimelow', 1, 18:00, 1780094, 1800094); ");


/** After Alarm has been triggered **/
db.execSQL("UPDATE MyTable SET triggered_at = 'TIME_TRIGGERED' ");

BroadcastReceiver (ReminderAlarmReceiver.class) 中,当您处理 alarmIntent 时,您可以更新列 triggered_at