0

我正在尝试使用setRepeating警报,但它对我不起作用。当我尝试使用一次性闹钟时,它对我有用。
下面是代码,请帮助我找出我做错的地方。

Toast.makeText(AndroidAlarmService.this, "Start Alarm", Toast.LENGTH_LONG).show();

Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class);
pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0);

AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 10);

//alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
calendar.getTimeInMillis() , 10, pendingIntent);
System.out.println("Calendar"+calendar.getTimeInMillis());          

谢谢,阿曼

4

2 回答 2

0

如果我们使用日历,我们必须使用 RTC 或 RTC_Wakeup。

于 2013-05-02T10:02:48.203 回答
0

您的setRepeating()方法中有不同的参考框架:

alarmManager.setRepeating(**AlarmManager.ELAPSED_REALTIME_WAKEUP**, **calendar.getTimeInMillis()** , 10, pendingIntent);

AlarmManager.ELAPSED_REALTIME 文档:

alarm clock in SystemClock.elapsedRealtime()

AlarmManager.RTC 文档:

alarm clock in Sustem.currentTimeMillis()

所以两者

alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() , 10, pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis() , 10, pendingIntent);

*_WAKEUP 类型也一样

于 2014-07-24T13:30:07.690 回答