小米手机删除最近使用的应用程序后,杀死了我的多个应用程序通知,但前台服务只能保留一个。该怎么办?
我正在编写一个提醒应用程序,它具有以下用例:
- 用户为 A 小时设置提醒
- 。用户为 B 小时设置提醒。A
- 小时到达,弹出提醒通知。用户不会忽略它。
- B 小时到来,弹出提醒通知。此时状态栏上有两个通知。
到目前为止,我一直在使用:
notificationManager.notify(
alarmId,
Notification.Builder(context, Constants.PRIMARY_CHANNEL_ID)
.setSmallIcon(R.drawable.idle_1)
.setCustomContentView(remoteViews)
.setOngoing(true)
.setContentIntent(notifyPendingIntent)
.setAutoCancel(false).build()
)
没有问题,但显然小米会在抛出通知的应用程序被删除时杀死通知从最近的事情来看。对于使用我的应用程序的所有小米设备来说,这将是一个严重错误;所以我尝试使用 ForegroundService
并应用这个 。
问题是使用 ForegroundService
不适用于处理多个通知:如果两个提醒启动服务,则最近的提醒通知将杀死并替换较早的通知。 (正如这个答案中所解释的)。你能看到我陷入的循环吗?
我的 ForegroundService
没什么大不了的,当我测试它时它工作得很好,但它有通知替换的东西。
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
// ...
startForeground(alarmId, notification)
return START_STICKY
}
目前我完全陷入困境:我是否错过了什么,或者我应该因此放弃小米手机所拥有的巨大市场份额?提前致谢!
I am writing a reminder app which has the following use case:
- The user sets up a reminder for hour A.
- The user sets up a reminder for hour B.
- Hour A arrives and the reminder notification pops up. The user does NOT dismiss it.
- Hour B arrives and the reminder notification pops up. Two notifications are on the status bar at that moment.
Until now, I was using:
notificationManager.notify(
alarmId,
Notification.Builder(context, Constants.PRIMARY_CHANNEL_ID)
.setSmallIcon(R.drawable.idle_1)
.setCustomContentView(remoteViews)
.setOngoing(true)
.setContentIntent(notifyPendingIntent)
.setAutoCancel(false).build()
)
Without a problem, but apparently Xiaomi kills notifications when the app that threw them gets removed from recents. This would be a critical error for all Xiaomi devices using my app; so I tried using a ForegroundService
and applying this.
The problem is using a ForegroundService
is not intended for handling multiple notifications: if two reminders start the service, the most recent reminder notification will kill and replace the earlier one. (As explained in this answer). Can you see the loop I'm trapped in?
My ForegroundService
is no big deal, it worked perfectly when I tested it but it has the notification replacement thing.
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
// ...
startForeground(alarmId, notification)
return START_STICKY
}
At the moment I'm completely stuck: am I missing something or should I just ditch the huge market share Xiaomi phones have due to this? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论