我正在尝试使用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());
谢谢, 阿曼
答案 0 :(得分:0)
如果我们使用日历,我们必须使用RTC或RTC_Wakeup。
答案 1 :(得分:0)
您的setRepeating()
方法中有不同的引用框架:
alarmManager.setRepeating(**AlarmManager.ELAPSED_REALTIME_WAKEUP**, **calendar.getTimeInMillis()** , 10, pendingIntent);
AlarmManager.ELAPSED_REALTIME docs:
alarm clock in SystemClock.elapsedRealtime()
AlarmManager.RTC docs:
alarm clock in Sustem.currentTimeMillis()
所以两者
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() , 10, pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis() , 10, pendingIntent);
* _WAKEUP类型
相同