java 使用警报管理器类安排警报

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 使用警报管理器类安排警报相关的知识,希望对你有一定的参考价值。

// Schedule an alarm for 8 a.m. in the morning

// Create a calender object to specify the time alarm has to be triggered
Calendar calendar = Calendar.getInstance();

calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 0);

// Create an intent to indicate which component should be triggered upon the alarm
// being triggered
Intent myIntent = new Intent(context, Receiver.class);
pendingIntent = PendingIntent.getBroadcast(context, 0, myIntent,0);

// Get an alarm manager object from the system service
AlarmManager alarmManager = (AlarmManager)this.getSystemService(ALARM_SERVICE);

// API 19 > non repeating single alarm trigger
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

// Repeating everyday alarm trigger (Won't run immediately)
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY, pendingIntent);

以上是关于java 使用警报管理器类安排警报的主要内容,如果未能解决你的问题,请参考以下文章