Create Notification each day

前端 未结 2 1713
失恋的感觉
失恋的感觉 2021-02-14 07:04

I want to create a Notification each Day at 8:00am. I have some data in a SQLite database and every day at this time I want to get the data from it and create a notification fro

相关标签:
2条回答
  • 2021-02-14 07:10

    You do not need a server. I think the best way to implement this is to use AlarmManager.

    Alarm Manager Example

    0 讨论(0)
  • 2021-02-14 07:32

    Use the Alarm manager class and put the notification in a NotifyService class. This will set an alarm at 8am everyday:

    Intent myIntent = new Intent(Current.this , NotifyService.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, 08);
    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
    
    0 讨论(0)
提交回复
热议问题