在特定日期和时间后重复警报。我怎么能避免?

时间:2017-10-10 07:09:59

标签: android alarmmanager

 AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    Intent notificationIntent = new Intent(this, AlarmReceiver2.class);
    PendingIntent broadcast = PendingIntent.getBroadcast(this, 100, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2017);
    cal.set(Calendar.MONTH, Calendar.OCTOBER);
    cal.set(Calendar.DAY_OF_MONTH, 10);
    cal.set(Calendar.HOUR_OF_DAY, 12);
    cal.set(Calendar.MINUTE, 30);
    cal.set(Calendar.SECOND, 0);

    Date sDate = cal.getTime();
    Toast.makeText(MainActivity.this, sDate + "", Toast.LENGTH_SHORT).show();
    alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), broadcast);

0 个答案:

没有答案