简体   繁体   English

Android-在前台运行应用程序时处理本地通知

[英]Android - Handle local notification when app in foreground

My app receives FCM and fires local notifications, which open target activities. 我的应用程序收到FCM并触发本地通知,从而打开目标活动。 This works fine if the local notification is clicked when the app is not running. 如果在未运行应用程序时单击本地通知,则此方法效果很好。

But, if the local notification is clicked when my app is already running (foreground or background), I don't want to open the target activity but shows an AlertDialog first. 但是,如果在我的应用程序已经运行(前台或后台)时单击了本地通知,则我不想打开目标活动,而是先显示AlertDialog。 So, the activities stack is not changed and the user can continue what he was doing before. 因此,活动堆栈不会更改,并且用户可以继续之前的操作。

It seems the local notification must have an action, which opens activities. 看来本地通知必须有一个操作才能打开活动。 Is there anyway achieve what I wanted above? 无论如何,有什么可以实现我上面想要的?

I think you have to stop sending push notification when you app is in foreground check if your app is in foreground or by following this link 我认为您必须在应用程序处于前台状态时停止发送推送通知,请检查您的应用程序是否处于前台状态或通过以下链接

check android application is in foreground or not? 检查android应用程序是否在前台?

check this in firebaseMessegingService class before sending PN and manage alert dialog appearance according that 发送PN之前,请在firebaseMessegingService类中进行检查,并根据提示管理警报对话框的外观

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

相关问题 应用程序在前台时如何处理Firebase通知 - How to handle the Firebase notification when app is in foreground 当app在前台时,GCM 3.0通知有效负载不显示android通知 - GCM 3.0 notification payload not showing android notification when app is in foreground FCM:当应用程序处于前台状态时处理其应用程序的不同数据通知 - FCM : Handling different data notification of an android app when app is in foreground 在Android中-当应用程序处于前台时如何防止Firebase推送通知? - In android - How to prevent Firebase push notification when app is in foreground? Android Notification Tap:当应用程序不在前台时进行片段过渡 - Android Notification Tap : Fragment transition when app not in foreground 当应用程序为前台时,Android通知正文不出现 - Android notification body doesn't appear when the app is foreground 当应用程序在前台时不显示通知 - Notification not showing when app is in foreground 当应用程序在 Android 上处于前台时不显示 Amazon Pinpoint 推送通知 - Amazon Pinpoint Push Notification not displayed when the app is in foreground on Android 应用程序在前台时需要在点击时关闭通知-Android - Need to dismiss the notification on tap when App is in foreground - android 如何检测 android 应用程序何时在后台和前台处理一些代码 - how to detect when android app in background and foreground to handle some code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM