我想创建一个警报,它会在预定的时间每天发生。我是否需要每小时创建一个PendingIntent并将其添加到AlarmManager中,或者有更简单的方法吗?
答案 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);
}