简体   繁体   English

确保即使未打开应用程序也能在 Android 上显示通知

[英]Ensure that notification show up on Android even if app is not opened

I am building an app that is needed for a research experiment.我正在构建一个研究实验所需的应用程序。 The experiment is entirely based on users responding to notifications that are shown at somehow random intervals.该实验完全基于用户对以某种随机间隔显示的通知的响应。 What is the best way to do this so that each notification will definitely be shown to the user?这样做的最佳方法是什么,以便每个通知肯定会显示给用户?

WHAT IS DONE SO FAR到目前为止做了什么

I have used AlarmManager and broadcast receiver but notifications stop showing up after some time.我使用了 AlarmManager 和广播接收器,但一段时间后通知停止显示。 Notification Channels (with id) are used too.也使用通知通道(带 id)。 I suspect the operating system removes the app after it has stayed in the background for a while.我怀疑操作系统会在应用程序在后台停留一段时间后将其删除。

Can anyone help to explain the best way to get the app to show notifications regardless?任何人都可以帮助解释让应用程序显示通知的最佳方式吗?

Since this is an app for research, users are well aware of any slow performances, or battery usage.由于这是一个用于研究的应用程序,用户很清楚任何性能缓慢或电池使用情况。 The only priority is to ensure that notifications show up.唯一的优先事项是确保显示通知。 Without this, the whole experiment will fail.没有这个,整个实验就会失败。

Any help or pointers will be great!任何帮助或指示都会很棒! Thanks!谢谢!

I'm not sure what method you've used to show notifications so I'm giving a general guidance.我不确定您使用什么方法来显示通知,因此我提供了一般指导。 You will need to use a background service which keeps running even after the app has closed.您将需要使用即使在应用程序关闭后仍会继续运行的后台服务 A background service can be killed by the android OS if its running low on memory, so you'll have to give permission to your app to autostart.如果后台服务内存不足,Android 操作系统可能会终止该服务,因此您必须授予应用程序自动启动的权限。 If you want even more reliability, you should use a Foreground service .如果您想要更高的可靠性,您应该使用Foreground 服务 This way you can give high priority to your notification service.通过这种方式,您可以为您的通知服务提供高优先级。

But it would be much simpler to integrate Firebase Cloud Messaging into your app than implementing your own NotificationBuilder service.但是,将Firebase Cloud Messaging集成到您的应用程序中要比实现您自己的 NotificationBuilder 服务简单得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果应用程序当前已打开,则显示警报而不是预定通知 - Show alert instead of scheduled notification if the app is currently opened Android 如果用户没有打开应用程序,应用程序运行通知 - Android app run notification if user has not opened app Android:排定的通知未显示? - Android: Scheduled Notification doesn't show up? 设置频道后,通知也不会显示在android O中 - Notification not showing in android O even after setting up with channel Android通知:打开应用程序时不显示通知吗? - Notification Android : Don't show notification when app is open? 我的通知仅在应用程序打开时有效 - My notification is only working when the app is opened 更新通知时设置ContentView最终会冻结应用程序? (机器人) - Setting ContentView when updating a notification eventually freezes up the app? (Android) Android通知会持续启动应用程序(即使我没有点击通知时)? - Android notification keeps launching app (even when I don't tap the notification)? 如何获取通知onesignal的内容并将其显示在我的Android应用程序中 - How to get content of notification onesignal and show it in my android app 如何在 android 上显示通知? - How to show notification on android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM