开发者

How to Call Alarm Manager at particular time?

here i used alarm manager to call service at particular time . I want to call that service at 23:59:00 . How can i call alarm manager at that particular time ? Please help me to solve this issue.

            Calendar calendar=Calendar.getInstance();
            calendar.add(Calendar.SECOND,what time to set);
            Intent intent=new Intent(getApplicationContext(),StartServiceAlaramReceiver.class);
            startAlaramServicePendin开发者_StackOverflowgIntent=PendingIntent.getBroadcast(getApplicationContext(),0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
            AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
            alarmManager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),startAlaramServicePendingIntent);


U can give time for alarmmanager using following way,

Intent activate = new Intent(this, AlaramActivity.class);
AlarmManager alarams ;
PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, activate, 0);
alarams = (AlarmManager) getSystemService(ALARM_SERVICE);
alarams.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis()+5000, alarmIntent);


I find using the JodaTime library for anything with respect to date and time.

Intent intent=new Intent(getApplicationContext(),StartServiceAlaramReceiver.class);
startAlaramServicePendingIntent=PendingIntent.getBroadcast(getApplicationContext(),0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
final DateTime todayE = (new DateTime()).minuteOfDay().withMaximumValue().minusMinutes(1);
AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,todayE.getMillis(),startAlaramServicePendingIntent);


The bellow link provide the detail description to set the Event that wil fire on the specified time. http://justcallmebrian.com/?p=129

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜