预定的Android重复通知有时会在APP重新启动上消失
在我的Xamarin表格项目中,我实施了iOS和Android的本地通知。
iOS通知按预期工作,在APP重新启动和设备重新启动后,计划重复通知仍在安排。
在Android上,尽管通知有时在App重新启动后消失,有时不会消失。我希望预定的重复通知不会从通知队列和Android中删除以处理该通知。
这就是我安排通知的方式:
var intent = new Intent(Application.Context, typeof(AndroidNotificationBroadcastReceiver));
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, int.Parse(id), intent, PendingIntentFlags.CancelCurrent);
var alarmManager = Application.Context.GetSystemService(Context.AlarmService) as AlarmManager;
alarmManager.SetRepeating(AlarmType.RtcWakeup, triggerTimeMilliSeconds, triggerIntervalMilliSeconds, pendingIntent);
这就是我检查哪些通知的方式:
var alarmIntent = new Intent(Application.Context, typeof(AndroidNotificationBroadcastReceiver));
return Enumerable
.Range(0, _maxNotifications)
.Where(index => PendingIntent.GetBroadcast(Application.Context, index, alarmIntent, PendingIntentFlags.NoCreate) != null)
通知IDS从0到63(_maxNotifications 64),
它可以安排,我可以收到通知,并且我可以收到它们,并且大多数时候我在我的大多数时候都可以接受。重新启动该应用程序,该通知仍是安排的,但有时它们消失了。 有什么问题?
编辑:这不是重新启动设备,而是仅重新启动应用程序。 triggerIntervalmilliseconds
是释放几天或几周,用于测试目的1或2分钟 setExActandallowwhileIdle
不是一个选项,因为我们需要重复通知
才能澄清:当我打开应用程序并安排一定日期和时间的重复通知时,我会收到该通知。我还将在设置的间隔中收到该通知的重复。我可以检查我发布的第二个代码是否有计划的通知。这将返回具有所有计划的通知ID的枚举。现在,当我关闭应用程序并重新打开应用程序时,第二个代码大部分时间都会像以前一样返回所有计划的通知ID,但有时第二个代码将返回一个空的枚举,表明计划的重复通知已以某种方式删除。
In my Xamarin Forms project I implemented local notifications for iOS and Android.
iOS notifications work as expected, scheduled repeating notifications are still scheduled after app restart and after device reboot.
On Android though notifications sometimes disappear after app restart, sometimes not. I would expect scheduled repeating notifications to not be dropped from the notification queue and Android to handle that.
This is how I schedule my notifications :
var intent = new Intent(Application.Context, typeof(AndroidNotificationBroadcastReceiver));
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, int.Parse(id), intent, PendingIntentFlags.CancelCurrent);
var alarmManager = Application.Context.GetSystemService(Context.AlarmService) as AlarmManager;
alarmManager.SetRepeating(AlarmType.RtcWakeup, triggerTimeMilliSeconds, triggerIntervalMilliSeconds, pendingIntent);
And this is how I check which notifications are scheduled:
var alarmIntent = new Intent(Application.Context, typeof(AndroidNotificationBroadcastReceiver));
return Enumerable
.Range(0, _maxNotifications)
.Where(index => PendingIntent.GetBroadcast(Application.Context, index, alarmIntent, PendingIntentFlags.NoCreate) != null)
Notification Ids go from 0 to 63 (_maxNotifications is 64)
It works, notifications are scheduled and I can receive them, and most of the time when I restart the app the notifications are still scheduled, but sometimes they are gone.
What could be the problem?
Edit: It's not about rebooting the device, it's about just restarting the app.triggerIntervalMilliSeconds
is days or weeks on release, for testing purposes 1 or 2 minutessetExactAndAllowWhileIdle
is not an option, because we need repeating notifications
To clarify : When I open my app and schedule a repeating notification for a certain date and time I will receive that notification. And I will also receive repeats of that notification in the interval I set. I can check if there are scheduled notifications with the second code I posted. This would return an Enumerable with all scheduled notification ids. Now when I close my app and reopen it, the second code MOST OF THE TIME will return an Enumerable with all scheduled notification ids as before, but SOMETIMES this second code will return an empty Enumerable, indicating that the scheduled repeating notification was somehow removed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论