我正在处理闹钟应用程序,一切正常,除了一件事。我的应用程序会触发警报,如果我设置为星期一设置的重复警报(当时间适合警报时它什么都不做)。可能是因为我使用调试但不是。我该怎么办呢?
我的代码:
int j = 0;
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent1 = new Intent(MyService_alarm.this,MyReceiver_Alarm.class);
if(string.length()>0) {
for (int i = string.length(); i > 0; i--) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute());
calendar.set(Calendar.SECOND, 0);
if (string.contains("1")) {
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
string = string.replace("1","");
Log.e("Point_1","Monday");
} else if (string.contains("2")) {
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek() + 1);
string = string.replace("2","");
Log.e("Point_1","Tuesday");
} else if (string.contains("3")) {
calendar.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
string = string.replace("3","");
Log.e("Point_1","Wednesday");
} else if (string.contains("4")) {
calendar.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
string = string.replace("4","");
Log.e("Point_1","Thursday");
} else if (string.contains("5")) {
calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
string = string.replace("5","");
Log.e("Point_1","Friday");
} else if (string.contains("6")) {
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
string = string.replace("6","");
Log.e("Point_1","Saturday");
} else if (string.contains("7")) {
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
string = string.replace("7","");
Log.e("Point_1","Sunday");
}
int y = intent.getIntExtra("Volume", 1);
intent1.putExtra("Size_ABC", y);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MyService_alarm.this, intent.getIntExtra("Size", 1) + j, intent1, 0);
alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), 7 * 24 * 60 * 60 * 1000, pendingIntent);
Log.e("Point_1", "Size is " + y);
Log.e("Point_1", "Time is " + calendar.getTime());
j++;
}
}else if(string.length() == 0){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute());
calendar.set(Calendar.SECOND, 0);
int y = intent.getIntExtra("Volume", 1);
intent1.putExtra("Size_ABC", y);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MyService_alarm.this, intent.getIntExtra("Size", 1), intent1, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
//Log.e("Point_1", "Size2 is " + y);
//Log.e("Point_1","Extra " + intent1.getIntExtra("Size_ABC",1));
Log.e("Point_1","Time is " + calendar.getTime());
}
我的日志显示设置闹钟的时间。
Time is Mon Nov 21 20:01:00 GMT+05:00 2016
11-27 20:00:27.477 13285-13285/com.SetAndGet.amadey.myapplication5 E/MediaPlayer﹕ Should have subtitle controller already set
11-27
20:00:27.497 // Time when alarm was triggered.
13285-13285/com.SetAndGet.amadey.myapplication5 E/Point_1﹕ Alarm!!!
可能有人遇到过这个问题并且已经知道了答案,请帮助我。
谢谢。