设置时间报警经理的Andr​​oid - 报警立即解雇经理、时间、oid、Andr

2023-09-06 06:06:03 作者:据为己有

可能重复:结果  Why在我的Andr​​oid报警经理发射瞬间?

我有这样的code,它将调用报警通知

I have this code which will call alarm notification

public static  Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.add(Calendar.HOUR_OF_DAY,hour);
cal.add(Calendar.MINUTE, min);
Intent intent = new Intent(this,  OnetimeAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, REQUEST_CODE, intent,0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() , pendingIntent); 
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();

但报警发射瞬间,它dosent给定的小时分钟后等待?我应该添加任何清单文件?

but the alarm is fired instantly , it dosent wait after the given hour and minutes ? should I add anything to to the manifest file ?

推荐答案

您使用当前时间设置报警。因此,它立即触发

You use the current time to set the alarm. So it fires instantly.

检查API。 http://developer.android.com/reference/android/app/AlarmManager.html#set%28int,%20long,%20android.app.PendingIntent%29

有你打发时间,当警报响起的作为第二个参数。在你的情况,这是实际时间。所以,你应该添加要等待的时间你的方法传递现在的时间。

There you pass the time when the alarm goes of as the second parameter. In your case this is the actual time. So you should add the amount of time you want to wait to the time your passing in the method right now.