I am trying to follow these steps on how to manage alarms and I need help!
Having a SQLite table etc. to properly track alarms, along with created,scheduled and triggered time stamps.
Here on in an answer on stackoverflow: AlarmMenager Checking if alarm already fired
So I have created my alarm to fire on specific days, which actually works. I insert the SQLite when alarm was set and other details.
But my issue is I need to update the Table in SQLite when the alarm precisely triggered. To update the "triggered_at
" column.
This is my below code that Fires ze alarm!
//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' ");