有什么方法可以在每台 Android 设备上创建可靠的循环通知吗?

发布于 2025-01-09 08:13:49 字数 395 浏览 1 评论 0原文

我想要创建的内容:一个离线应用程序,每 5 天随机从数据库(房间)向用户发送一条文本通知。我在真实设备 Redmi Note 7 (MIUI) 上测试了该应用程序。

因此,我尝试使用警报管理器和工作管理器来重复任务,但只有如果我为应用程序启用自动运行并禁用黄油优化,它才能正常工作(即使应用程序被终止)。然后我发现许多制造商,如小米、Oppo、华为等,都限制应用程序的后台工作。

我有 2 个问题:

  1. 我应该使用什么来在每个 Android 设备上编写可靠的重复通知(不使用前台服务),而不要求用户启用自动运行和类似的应用程序设置?
  2. Twitter 和 Telegram 等应用程序如何在不启用额外设置的情况下发送通知,尽管它们与我的应用程序不同使用互联网

What I want to create: An offline app that sends a text notification to user from the database (Room) once every 5 days at a random time. I test the app on my real device Redmi Note 7 (MIUI).

So I tried to use Alarm Manager and Work Manager for repeating task but it only worked right (even app is killed) if I enabled autorun and disabled buttery optimization for my application. Then I found out that many manufacturers like Xiaomi, Oppo, Huawei and similar restrict background work for apps.

I have 2 questions:

  1. What should I use to write reliable recurring notifications (not with foreground service) on every android device without requesting users to enable autorun and similar app settings?
  2. How apps like Twitter and Telegram sends notifications without enabling extra settings, although they use the internet unlike my app

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久而酒知 2025-01-16 08:13:49

Twitter 等使用 FCM 发送高优先级推送通知。设备上正在休眠等待来自套接字的输入的进程接收它并启动他们的应用程序(该进程是 Android 的一部分,他们不编写它)。

如果后台处理简短且偶尔,您应该能够在 Android 上可靠地进行后台处理。 WorkManager、JobScheduler 和 AlarmManager 都可以实现此目的,根据您的需求,其中一些比其他更好。我建议您编辑或开始一个新问题,其中包含您所说的不起作用的代码以及它需要运行的频率的准确描述。

Twitter and the like use FCM to send a high priority push notification. A process on the device which is sleeping waiting on input from a socket receives it and starts their app (that process is part of Android, they don't write it).

You should be able to reliably do background processing on Android if its brief and occassional. WorkManager, JobScheduler, and AlarmManager would all work for that, with some better than others depending on your needs. I suggest you either edit or start a new question with the code you said wasn't working and an accurate description of how often it needs to run.

孤独患者 2025-01-16 08:13:49

因此,我发现无法通过每个 Android 设备上的 Alarm Manager 或 Work Manager 离线发送可靠的重复通知。我使用 FCM,一切都很好

So, I found out that there is no way to send reliable recurring notifications offline via Alarm Manager or Work Manager on every android device. I use FCM and everything works great

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文