gpt4 book ai didi

Android GCM(推送通知): device doesn't receive notification if application is stopped

转载 作者:IT老高 更新时间:2023-10-28 23:12:06 24 4
gpt4 key购买 nike

我在我的 Android 项目中使用推送通知 (GCM)。

根据 GCM 教程,我实现了广播接收器并将其注册在 AndroidManifest.xml 中。

即使我的应用程序关闭,这种广播接收器也应该接收消息(不仅当我的应用程序在后台,而且即使它被强制停止)。

但它并没有像我预期的那样工作。如果应用程序关闭,则不会调用 onReceive() 方法。看来我对广播接收器的理解是正确的,问题出在我对 GCM 的期望中。

其中一个可能的原因是,如果应用程序关闭,谷歌服务器甚至不会向设备发送通知。那么,仅当我的应用程序正在运行或在后台(但未关闭)时,我的应用程序才能接收消息(并且 onReceive() 方法将在广播接收器中调用)是否正确?

提前致谢。

最佳答案

This kind of broadcast receivers should receive messages even if my app is closed (not only if my app is in background but even if it was force stopped).

如果用户从设置中强制停止您的应用,您的代码将永远不会再次运行,直到手动运行您的组件之一,通常是用户手动启动一个 Activity (从 Android 3.1 开始) )。因此,如果用户从“设置”中强制停止您的应用,您将不会在较新的设备/模拟器上收到 GCM 消息。

So, is it correct that my app can receive a message (and onReceive() method will be invoked in broadcast receiver) only if it's running or in background (but not closed)?

从应用程序的角度来看,Android 中没有“关闭”的概念。如果“关闭”的意思是“没有正在运行的进程,最后一个进程正常终止”,那么是的,你应该收到 GCM 消息和其他广播。但是,同样,强制停止不是“正常终止”。

关于Android GCM(推送通知): device doesn't receive notification if application is stopped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12073449/

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