如何在给定时间停止报警?

时间:2014-11-17 14:14:20

标签: android

我使用AlarmManager.i在android中编写了调度程序。使用以下方法启动警报。

    AlarmManager manager = (AlarmManager) getApplicationContext()
            .getSystemService(Context.ALARM_SERVICE);
    int interval = 1000 * 60 * initailDelay;
    manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis(), interval, pendingIntent);
    Toast.makeText(getApplicationContext(), "Alarm Set", Toast.LENGTH_SHORT)
            .show();

现在我想在给定时间停止闹钟?例如我必须在6点开始闹钟并在6.30结束闹钟。

1 个答案:

答案 0 :(得分:0)

添加以下行:

AlarmManager manager = (AlarmManager) getApplicationContext()
        .getSystemService(Context.ALARM_SERVICE);
int interval = 1000 * 60 * initailDelay;
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
        System.currentTimeMillis(), interval, pendingIntent);
Toast.makeText(getApplicationContext(), "Alarm Set", Toast.LENGTH_SHORT)
        .show(); 
manager.cancel(pendingIntent);