利用闹钟alarmmanager来定时的发送通知,在通知栏显示,点击后跳转到指定activity
2022-05-26 11:09:02 1.99MB android 定时提醒 通知
1
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