Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓-警报管理器每天运行_Android - Fatal编程技术网

Android 安卓-警报管理器每天运行

Android 安卓-警报管理器每天运行,android,Android,我不明白出了什么问题,但我的闹钟每天都在响,即使我硬编码了日期,我也不知道发生了什么 Intent notificationIntent = new Intent(AddTask.this,CustomBroadcastReceiver.class); notificationIntent.putExtra(Intent.EXTRA_UID,newTaskId); PendingIntent pendingIntent = PendingIntent.getBroadcast(AddTask.t

我不明白出了什么问题,但我的闹钟每天都在响,即使我硬编码了日期,我也不知道发生了什么

Intent notificationIntent = new Intent(AddTask.this,CustomBroadcastReceiver.class);
notificationIntent.putExtra(Intent.EXTRA_UID,newTaskId);
PendingIntent pendingIntent = PendingIntent.getBroadcast(AddTask.this, newTaskId, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(getApplicationContext().ALARM_SERVICE);

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.DAY_OF_WEEK,2);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY * 7, pendingIntent);

今天是星期天,所以天数是1,我写了calendar.set(calendar.day\u OF_WEEK,2);自从我用了这一刻的时间和分钟,警报就被触发了。。。无论我是否设置了第1天、第2天、第3天、第4天、第5天或第6天,或者即使我制作了多个具有相同ID的报警管理器,并且每个报警管理器都包含每隔一天触发的报警,这都无关紧要。为什么需要这一行

calendar.setTimeInMillis(System.currentTimeMillis());
此外,android开发建议使用

setInexactRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation);
编辑: 我怀疑创建警报的目的没有设定,因此没有正确创建警报。 也许这会奏效:

Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_ONE_SHOT);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
//set repeating alarm here

我希望这能回答这个问题。

好吧,我已经解决了这个问题,对于每个想创建这样一个报警应用程序的人来说>你设置触发报警的时间、小时和星期几,它的工作原理是这样的:如果今天是你选择的日子,你只需使用以下设置报警:

calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
但是,如果您选择的日期不是今天,您必须输入最近选择的日期,然后如上所述设置额外的小时和分钟


这是使它工作的唯一方法

它不工作我将报警日期设置为3,今天的数字为1,它刚刚触发。我已经随着你改变了一切said@uplnypan你找到解决办法了吗?没有,我很难过。。。我不知道出了什么问题,我只想在给定的时间和一周中的某一天永远重复警报,直到警报被删除。