简体   繁体   English

用户关闭应用程序时如何启用推送通知,用户打开应用程序时如何禁用推送通知

[英]How to Enable Push notification when user closes App and disable when user open app

There is a problem that I am using OneSignal for push notification in my app, I want onesignal's NotificationExtenderService should start when user closes the app and stop when user opens app 我在应用程序中使用OneSignal进行推送通知时遇到问题,我希望onesignal的NotificationExtenderService应该在用户关闭应用程序时启动,并在用户打开应用程序时停止

in other words,disable service when app is launched and enable when app is closed, 换句话说,在启动应用程序时禁用服务,在关闭应用程序时启用服务,

Please Help! 请帮忙!

Since you tagged with Firebase, I assume that Firebase Cloud Messaging (FCM) is involved. 由于您已用Firebase标记,因此我假定涉及Firebase Cloud Messaging(FCM)。 FCM has two message types: FCM有两种消息类型:

  • Notification messages 通知讯息
  • Data messages 数据信息

Notification messages are handed by the system when you app isn't active, and delivered to your code when the app is active. 通知消息是由系统交给你时,应用程序是不活跃的,当应用程序激活发送到您的代码。 This means that in its default behavior (ie if you only add the SDK and no custom code to the app) shuld be precisely what you describe: 这意味着,按照其默认行为(即,如果您仅添加SDK且没有向应用程序添加自定义代码)应该正是您所描述的内容:

  • If the app is not active, incoming notifications are displayed in the system tray. 如果该应用程序未激活,则传入通知将显示在系统托盘中。
  • If the app is active, incoming notifications are not displayed. 如果该应用程序处于活动状态,则不会显示传入通知。

Data messages are always deliver to the code in your app. 数据消息始终传递到应用程序中的代码。 This means that you code can determine whether to display a notification or not. 这意味着您的代码可以确定是否显示通知。

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

相关问题 即使用户在 android studio 中关闭应用程序,如何保持登录状态 - How to remain signed in even when the user closes the app in android studio 单击推送通知时打开应用 - Open app when clicking push notification 当应用程序无法在后台运行时,如何在点击推送通知中打开网址 - how to open url on click push notification when app is not working in background 当用户点击推送通知消息时,我的应用程序启动。 如何使应用程序完整显示推送消息? - When user taps on the push notification message, my app launches. How to make the app display the push message in full? 当应用是更改的所有者时禁用 Google 日历推送通知 - Disable Google Calendar Push Notification when app is an owner of the change 当用户打开预选的应用程序时提醒用户 - Alert user when they open a preselected app 应用打开时调用哪种方法? 当应用关闭时? - Which method is called when app open? And when app closes? 当应用程序关闭时停止通知被销毁 - Stop Notification from being destroyed when the app closes 仅当应用程序在后台时发送推送通知 - Sending a push notification only when app is in background 即使应用程序被杀死也推送通知 - Push Notification even when app is killed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM