private void setReminder(boolean b) {
// get the AlarmManager instance
AlarmManager am= (AlarmManager) getSystemService(ALARM_SERVICE);
// create a PendingIntent that will perform a broadcast
PendingIntent pi= PendingIntent.getBroadcast(MainActivity.this, 0, new Intent(this,MyReceiver.class), 0);
if(b){
// just use current time + 10s as the Alarm time.
Calendar c=Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
//可以根据项目要求修改,秒、分钟、提前、延后
c.add(Calendar.SECOND, 10);
// schedule an alarm
am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(),pi);
}
else{
// cancel current alarm
am.cancel(pi);
}
}
2022-04-05 23:06:17
1.99MB
定时推送通知
1