Service run on specific Time Android

前端 未结 1 1122
小鲜肉
小鲜肉 2021-01-16 14:02

I am trying to run service on every day only on Specific time, lets say every day 8 :00 am and here I found two methods as

public static void setScheduleMes         


        
相关标签:
1条回答
  • 2021-01-16 14:08

    Have a look Alarms
    @ RTC examples

    // Set the alarm to start at approximately 2:00 p.m.
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 14);
    
    // With setInexactRepeating(), you have to use one of the AlarmManager interval
    // constants--in this case, AlarmManager.INTERVAL_DAY.
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, alarmIntent);
    

    or

    In your code

    alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY, pintent);
    

    replace

    AlarmManager.INTERVAL_DAY

    to

    24 * 60 * 60 * 1000

    . which means repeat alarm exactly after 24 hours

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