Samsung Electronics logo

Checking for Alarm Events



Learning how to check for the next alarm to be triggered is a basic alarm management skill:

  1. Create an absolute alarm:

    /* Alarm is triggered at 8:00 on April 4, 2012 */
    var alarm = new webapis.AlarmAbsolute(new Date(2012, 3, 4, 8, 0)); 
    webapis.alarm.add(alarm, "com.samsungapps.browser");
    
    
  2. Use the getNextScheduledDate() method to retrieve the time and date of the next absolute alarm to be triggered:

    console.log("The alarm will trigger at " + alarm.getNextScheduledDate());
    
  3. Create a relative alarm:

    /* Alarm is triggered in 3 hours */
    var alarm = new webapis.AlarmRelative (3 * webapis.alarm.PERIOD_HOUR); 
    webapis.alarm.add(alarm, "com.samsungapps.browser");
    
  4. Use the getRemainingSeconds() method to retrieve the number of seconds till the next relative alarm is triggered:

    console.log("The alarm triggers " + alarm.getRemainingSeconds() + " seconds later");