说到“一些示例代码”并不是那么容易
AlarmManager。
以下是显示的设置的代码段
AlarmManager:
AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);Intent i=new Intent(context, OnAlarmReceiver.class);PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), PERIOD, pi);
在此示例中,我正在使用
setRepeating()。如果你想要一键式警报,则只需使用set()。确保给警报的启动时间与在的初始参数中使用的时间相同
set()。在上面的示例中,我正在使用
AlarmManager.ELAPSED_REALTIME_WAKEUP,因此我的时基为
SystemClock.elapsedRealtime()。



