gpt4 book ai didi

android - FCM 启动器 Activity 并不总是打开

转载 作者:太空狗 更新时间:2023-10-29 14:46:48 29 4
gpt4 key购买 nike

我在 Android 上使用 Firebase 云消息传递时遇到了以下问题。当应用程序在后台处理收到的通知时,会发生这种情况。文档说明如下:

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.

This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

尽管这是大多数时候发生的情况,但我发现了一些未打开启动器 Activity 的边缘情况。相反,应用程序只是在后台堆栈中的最后一个 Activity 上从后台恢复,让我无法获得有效负载。

我每次都可以通过终止进程并通过系统托盘的通知打开应用程序来重现此问题。第一次点击通知时,启动器 Activity 会按照文档中的描述打开,但是通过点击任何后续通知,应用程序会简单地恢复,而无需先通过启动器 Activity。

我不确定是我做错了什么,还是 Firebase 的 SDK 中存在错误。您知道为什么会发生这种情况吗?

我正在测试的通知是一个显示消息通知(不是数据通知),它也有一个负载。

{
"to": "d-3qyvyqefU:APA91bG_nHNYeYuKwB3oIvRKStVgSyelTIhX6rtu6LGPAjgo-LGDVk9iFO5LWZ-XFMeeRVkZm0suMyJAnWORWbZlMaVcHmhFTZOKPI_A-D2wYXM0SIIT8pZZ2g4W55S1bz9YD5y625fv",
"priority": "high",
"content_available": true,
"registration_id": "d-3qyvyqefU:APA91bG_nHNYeYuKwB3oIvRKStVgSyelTIhX6rtu6LGPAjgo-LGDVk9iFO5LWZ-XFMeeRVkZm0suMyJAnWORWbZlMaVcHmhFTZOKPI_A-D2wYXM0SIIT8pZZ2g4W55S1bz9YD5y625fv",
"collapse_key": "Collapse Key",
"data": {
"type": "default",
"person": "2123435",
"token": "asdmmio23j4123azde3"
},
"notification": {
"type": "default",
"title": "Howdie!",
"body": "Say hi to your new friend!"
}
}

最佳答案

对于所有仍然面临这个问题的人来说,FirebaseMessagingService 类中有一个方法公开了一个 Intent 对象。您可以覆盖它并执行如下操作:

@Override
protected int zzaa(Intent intent) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return super.zzaa(intent);
}

上面的代码应该可以解决这个问题,但 Firebase 的人很可能会在未来更改访问修饰符——如果他们还没有的话。我已经在他们那边开了一张票,并确认他们可以重现这种行为,并会在某个时候修复这个错误。

关于android - FCM 启动器 Activity 并不总是打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39244903/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com