如何在2到3天后发出警报

时间:2018-03-15 15:35:29

标签: android notifications alarm

当用户注册项目时,我需要每2天执行一次通知,如果用户没有使用该应用程序,则每3天执行一次通知。

目前我正在使用它来设置闹钟通知

Calendar calendar1 = Calendar.getInstance();
    calendar1.set(Calendar.HOUR_OF_DAY, 7);
    calendar1.set(Calendar.MINUTE, 0);
    calendar1.set(Calendar.SECOND, 0);
    if (calendar1.before(calendar))
        calendar1.add(Calendar.DATE, 1);
    Intent intent = new Intent(this, Dog_alert1.class).setAction("dog1");
    PendingIntent dog1 = PendingIntent.getBroadcast(this, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    final AlarmManager alarm1 = (AlarmManager) getSystemService(ALARM_SERVICE);
    if (Build.VERSION.SDK_INT >= 19) {
        alarm1.setExact(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(), dog1);
    } else {
        alarm1.set(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(), dog1);
    }

现在我怎样才能在3天后发出此警报?

0 个答案:

没有答案