Android闹钟每天都有几天

时间:2015-08-12 17:01:11

标签: android

我想创建一个警报,它会在预定的时间每天发生。我是否需要每小时创建一个PendingIntent并将其添加到AlarmManager中,或者有更简单的方法吗?

1 个答案:

答案 0 :(得分:1)

我使用待定意图

设置这样的闹钟
private void setAlarm(Calendar targetCal) {

    textAlarmPrompt.setText("\n\n***\n" + "Alarm is set "
            + targetCal.getTime() + "\n" + "***\n");

    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
            getBaseContext(), RQS_1, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),
            pendingIntent);

}