Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 1.16 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Setting a notification to fire at a specific time in Android
  2. //---use the AlarmManager to trigger an alarm---
  3.         AlarmManager aMan = (AlarmManager) getSystemService(ALARM_SERVICE);
  4.  
  5.             //---get current date and time---
  6.         Calendar alCal = Calendar.getInstance();
  7.         //---sets the time for the alarm to trigger---                      
  8.         alCal.set(Calendar.HOUR_OF_DAY, 23);            
  9.         alCal.set(Calendar.MINUTE, 41);                
  10.         alCal.set(Calendar.SECOND, 00);
  11.  
  12.         Intent noteIntent = new Intent(this, Splash.class);
  13.         PendingIntent pendI = PendingIntent.getActivity(this, 0, noteIntent, 0);
  14.         long fireTime = System.currentTimeMillis();
  15.         String noteBody = "notification body";
  16.         String noteTitle = "notification title";
  17.         Notification note = new Notification(R.drawable.noteicon, noteTitle, fireTime);
  18.         note.setLatestEventInfo(this, noteTitle, noteBody, pendI);
  19.         note.defaults = Notification.DEFAULT_SOUND;
  20.         noteman.notify(uniqueID, note);
  21.         //---sets the alarm to trigger---
  22.         aMan.set(AlarmManager.RTC_WAKEUP, alCal.getTimeInMillis(), pendI);
  23.         finish();