我很难找到关于闹钟的特定日子,并且每天都会请求能帮助我的人 并使用这些代码有什么错误,运行每一次所以我发送dayOfWeek = 1;但每天都跑步
public void setAlarm(int dayOfWeek) {
Toast.makeText(getApplicationContext(), dayOfWeek+","+h+","+m, 22222).show();
cal1.set(Calendar.DAY_OF_WEEK, dayOfWeek);
cal1.set(Calendar.HOUR, 11);
cal1.set(Calendar.MINUTE, 0);
cal1.set(Calendar.SECOND, 0);
cal1.set(Calendar.MILLISECOND, 0);
Intent intent = new Intent(this, RemmemberActivity.class);
PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0,
intent, 0);
pendingIntent = PendingIntent.getActivity(this, 12345,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
Long alarmTime = cal1.getTimeInMillis();
am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,24 * 60 * 60 * 1000 , pendingIntent);
}
答案 0 :(得分:0)
在快速查看之后我可以看到你在这一行设置闹钟重复每24小时:
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,24 * 60 * 60 * 1000 , pendingIntent);
您的dayOfWeek
仅用于第一次关闭的时间。
如果你有一个警报应该在同一时间每周发生三次,请发出三次警报,每周重复一次。
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, 7 * 24 * 60 * 60 * 1000 , pendingIntent);
答案 1 :(得分:0)
最后这个正确的解决方案,如果设置为(sun,tus,fri),你必须为这三天创建三个警报 以下代码在每个星期日设置闹钟并发送dayOfWeek = 1; 重要提示每天创建一个运行必须在每个intnet中更改请求代码(12345) 在例子中
public void setAlarm_sun(int dayOfWeek) {
cal1.set(Calendar.DAY_OF_WEEK, dayOfWeek);
Toast.makeText(getApplicationContext(), "sun "+cal1.get(Calendar.DAY_OF_WEEK), 222).show();
Toast.makeText(getApplicationContext(), "Finsh", 222).show();
Intent intent = new Intent(this, SecActivity.class);
PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0,
intent, 0);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 12345,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
Long alarmTime = cal1.getTimeInMillis();
AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
// am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,7* 24 * 60 * 60 * 1000 , pendingIntent);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,7* 24 * 60 * 60 * 1000 , pendingIntent);
}