Created
December 13, 2011 16:22
-
-
Save fumingshih/1472753 to your computer and use it in GitHub Desktop.
How to user AlarmManager to set the application running at scheduled time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Calendar cur_cal = new GregorianCalendar(); | |
cur_cal.setTimeInMillis(System.currentTimeMillis());//set the current time and date for this calendar | |
Calendar cal = new GregorianCalendar(); | |
cal.add(Calendar.DAY_OF_YEAR, cur_cal.get(Calendar.DAY_OF_YEAR)); | |
cal.set(Calendar.HOUR_OF_DAY, 18); | |
cal.set(Calendar.MINUTE, 32); | |
cal.set(Calendar.SECOND, cur_cal.get(Calendar.SECOND)); | |
cal.set(Calendar.MILLISECOND, cur_cal.get(Calendar.MILLISECOND)); | |
cal.set(Calendar.DATE, cur_cal.get(Calendar.DATE)); | |
cal.set(Calendar.MONTH, cur_cal.get(Calendar.MONTH)); | |
Intent intent = new Intent(ProfileList.this, IntentBroadcastedReceiver.class); | |
PendingIntent pintent = PendingIntent.getService(ProfileList.this, 0, intent, 0); | |
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE); | |
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30*1000, pintent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment