Set notification to specific time

后端 未结 2 1852
醉酒成梦
醉酒成梦 2020-12-04 13:32

I would like my notification to run at 12:00pm everyday. How do you replace the when value with a time?

NotificationManager nm = (NotificationManager) getSys         


        
相关标签:
2条回答
  • 2020-12-04 14:12

    The when parameter is for sorting the notifications in the status bar. You should code your app such that it fires the notification at the desired time.

    0 讨论(0)
  • 2020-12-04 14:35

    You can use an alarm manager

    Intent myIntent = new Intent(ThisApp.this , myService.class);     
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    pendingIntent = PendingIntent.getService(ThisApp.this, 0, myIntent, 0);
    
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 00);
    calendar.set(Calendar.SECOND, 00);
    
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent);  //set repeating every 24 hours
    

    and put the notification inside myService class!

    0 讨论(0)
提交回复
热议问题