
Untitled
By: a guest on
Aug 1st, 2012 | syntax:
None | size: 1.16 KB | hits: 17 | expires: Never
Setting a notification to fire at a specific time in Android
//---use the AlarmManager to trigger an alarm---
AlarmManager aMan = (AlarmManager) getSystemService(ALARM_SERVICE);
//---get current date and time---
Calendar alCal = Calendar.getInstance();
//---sets the time for the alarm to trigger---
alCal.set(Calendar.HOUR_OF_DAY, 23);
alCal.set(Calendar.MINUTE, 41);
alCal.set(Calendar.SECOND, 00);
Intent noteIntent = new Intent(this, Splash.class);
PendingIntent pendI = PendingIntent.getActivity(this, 0, noteIntent, 0);
long fireTime = System.currentTimeMillis();
String noteBody = "notification body";
String noteTitle = "notification title";
Notification note = new Notification(R.drawable.noteicon, noteTitle, fireTime);
note.setLatestEventInfo(this, noteTitle, noteBody, pendI);
note.defaults = Notification.DEFAULT_SOUND;
noteman.notify(uniqueID, note);
//---sets the alarm to trigger---
aMan.set(AlarmManager.RTC_WAKEUP, alCal.getTimeInMillis(), pendI);
finish();