我有以下代码来设置闹钟。它适用于单个日期。但在我的应用程序中,用户可以选择多个日期,当他/她选择多个日期时,我必须在每个选定日期设置闹钟选择time.eg-如果用户选择三个日期11,12,13并选择时间8am然后闹钟应该在11,12,13上午8点响铃以下是我的代码我在哪里为单个日期设置闹钟
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.YEAR, 2016);
calendar.set(Calendar.DAY_OF_MONTH, 11);
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());
Intent myIntent = new Intent(MainActivity.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0);
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
答案 0 :(得分:1)
为每个PendingIntent
使用不同的请求代码
final int requestId = (int) System.currentTimeMillis();
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, requestId, myIntent, 0);