我正在尝试使用AlarmManager为通知设置警报。当用户选择一个列表项目时设置警报,所以我试图每次都设置一个单独的警报(使用传递给pendingIntent的唯一ID)选择一个列表项目。setExact方法调用被跳过。警报未按预期方式被触发
用于设置报警代码:
public static void setAlarm(Context context, Movie movie, Schedule schedule){
Intent arg = new Intent(context, NotifyService.class);
arg.putExtra(NotificationHelper.fetch_schedule_id, schedule.getId());
arg.putExtra(NotificationHelper.fetch_movie_id, movie.getId());
PendingIntent pendingIntent = PendingIntent.getService(context.getApplicationContext(), (int) schedule.getId(), arg, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
am.setExact(AlarmManager.RTC_WAKEUP, schedule.getStart().getTime(), pendingIntent);
else
am.set(AlarmManager.RTC_WAKEUP, schedule.getStart().getTime(), pendingIntent);
}
的问题我负责的是呼叫设置(或setExact)方法没有在时间执行。它的工作一半的时间,但在特定的情况下,像,当用户点击两个或多个列表项,一个后在不到一秒钟的另一个,那么只有第一次调用执行和调用剩下的只是忽略。
另外,由于set/setexact方法返回void如果调用方法并设置了警报,则无法调试。现在我必须每次检查adb shell dumpsys报警。
所以,如果有人能告诉我如何安排的警报,使得每次触发,无论多么频繁调用该方法,甚至指导我在正确的方向,这将会是一个很大的帮助。 :)
其实这个问题不是特定设备。我已经在很多设备上测试过该应用,但仍然面临着这个错误。而对于我描述的用例来说,警报根本不会触发。 –
好吧,也许你有一个不同的错误,虽然你会面对我描述的错误。另外,你可以附加更多的代码; – Vasilisfoo