[英]Notifications when the app is turned off
I wonder if it is possible to have notifications show up even if the app is turned off. 我想知道即使关闭了应用程序,是否也可能显示通知。
say for example I have an app and I set some kind of notification for 13.00 the next day and then turn the app off or restart my phone or something. 例如说我有一个应用程序,第二天我为13.00设置了某种通知,然后关闭该应用程序或重新启动我的手机或其他东西。
Is it possible to still get a notification in the notification bar with some text that starts the app or do the app need to run in the background to be able to use notifications? 是否仍可能在通知栏中收到带有一些可启动应用程序的文本的通知,或者该应用程序需要在后台运行才能使用通知?
if it is possible, what is the best way to do this? 如果可能的话,最好的方法是什么? (get a notification at a certain time that starts the app) and if not, how do you recommend doing notifications? (在启动应用程序的特定时间获得通知),如果没有,您如何建议进行通知?
The type of notifcations I want to do are reminder notifications. 我想做的通知类型是提醒通知。
thanks for all help! 谢谢大家的帮助!
AlarmManager和Service的组合将帮助您执行您正在寻找的任务,我已经执行了此操作。请查看android教程。
What you're looking for is a background service. 您正在寻找的是后台服务。 See this Android Services tutorial . 请参阅此Android服务教程 。
In the background service, your app should check periodically and when necessary, create and issue new notifications. 在后台服务中,您的应用应定期检查,并在必要时创建并发布新通知。 See this Android Notifications tutorial . 请参阅此Android Notifications教程 。
The background service can be set to automatically start when the phone is restarted, and to re-issue any uncleared notification again. 可以将后台服务设置为在重新启动电话时自动启动,并重新发出任何未清除的通知。
Many apps such as Gmail already do this. Gmail等许多应用程序已经可以执行此操作。 Although you must be careful in resource usage or Android might kill your service. 尽管您必须谨慎使用资源,否则Android可能会终止您的服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.