在android中设置每年的重复警报

时间:2018-01-18 18:24:29

标签: android alarmmanager alarm android-alarms repeatingalarm

我正在android中构建一个警报应用程序。现在我可以为每天,每周和每个月创建重复警报。

现在我的要求是每年设置重复警报。 TIA

2 个答案:

答案 0 :(得分:1)

您可以在每年之后设置闹钟,每次闹钟触发,您都可以开始新的服务意图,这将在下一年连续设置闹钟。

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
int year = calendar.get(Calendar.YEAR);
calendar.set(Calendar.YEAR, year + 1);

alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 0, alarmIntent);

答案 1 :(得分:0)

可能这是答案https://developer.android.com/training/scheduling/alarms.html

func placeAutocomplete(resultsViewController: GMSAutocompleteViewController) {
    var placeClient = GMSPlacesClient()
    let filter = GMSAutocompleteFilter()
    filter.country = "USA"
    filter.type = .region

    resultsViewController.autocompleteFilter = filter 

我认为你可以为明年设置警报,当时间到来时,内部运行并设置年份+ 1的警报,这可以使它每年重复

// 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);