设备停止接收GCM推送,直到网络切换为止

rot*_*egg 8 android push-notification google-cloud-messaging

我有一个依赖于GCM推送通知的Android应用程序,有时,用户的设备将停止接收推送通知.这种行为是非常间歇性的:在某些设备上,它永远不会失败并且只能继续工作数周或数月,而在其他设备上,它将工作几天,然后随机停止接收推送.

每次设备停止工作时,我都验证了设备有一个来自GCM的有效regId,并且我的服务器正在发送推送到该regId.但是,日志显示设备未接收任何内容.以下是正常推送接收的日志:

05-15 10:39:21.091: V/GCMBroadcastReceiver(13766): onReceive: com.google.android.c2dm.intent.RECEIVE
05-15 10:39:21.091: V/GCMBroadcastReceiver(13766): GCM IntentService class: com.medigram.v2.GCMIntentService
05-15 10:39:21.091: V/GCMBaseIntentService(13766): Acquiring wakelock
05-15 10:39:21.111: V/GCMBaseIntentService(13766): Intent service name: GCMIntentService-468134393228-13
05-15 10:39:21.131: V/GCMBaseIntentService(13766): Releasing wakelock
05-15 10:39:21.171: V/GCMBroadcastReceiver(13766): onReceive: com.google.android.c2dm.intent.RECEIVE
05-15 10:39:21.171: V/GCMBroadcastReceiver(13766): GCM IntentService class: com.medigram.v2.GCMIntentService
05-15 10:39:21.171: V/GCMBaseIntentService(13766): Acquiring wakelock
05-15 10:39:21.241: V/GCMBaseIntentService(13766): Intent service name: GCMIntentService-468134393228-14
05-15 10:39:21.271: V/GCMBaseIntentService(13766): Releasing wakelock
Run Code Online (Sandbox Code Playgroud)

这些都不会出现在已停止接收推送的设备上,因此,我的GCMIntentService的onMessage()方法都没有被调用.

奇怪的是,当我将设备连接从3G/4G切换到wifi或反之亦然时,它再次开始工作,设备立即获得所有积压推送.连接类型发生变化时会发生什么?

万一它有帮助,这里有一些我尝试过的设备,其中push正在努力手动重现问题,但无济于事:

- 我首先认为它可能是一个上下文问题,但当简单地切换网络解决了这个问题时,很快就被排除了.无论如何,我尝试使用"不要保持活动"开发人员选项进行进一步调查,然后对应用程序进行后台处理,但这对推送没有任何影响.

- 我已经尝试强制停止应用程序以查看是否会导致推送停止工作,但问题似乎与强制停止的应用程序没有任何关系,因为它继续工作.

- 我已经尝试将手机置于飞机模式并返回,但推动仍在继续工作.

如果有人能指出我正确的方向,我会非常感激,因为我已经耗尽了stackoverflow和google上的所有资源.当我开始时,我仍然对这个问题一无所知.

Nis*_*war 0

通常,Android 在移动连接上每 28 分钟发送一次心跳,在 Wifi 上每 15 分钟发送一次心跳,因此您可以通过从应用程序以更短的时间间隔广播这两个意图来解决此问题。

com.google.android.intent.action.MCS_HEARTBEAT

com.google.android.intent.action.GTALK_HEARTBEAT

        Intent intent = new Intent("com.google.android.intent.action.MCS_HEARTBEAT");
        Intent intent1 = new Intent("com.google.android.intent.action.GTALK_HEARTBEAT");
        sendBroadcast(intent);
        sendBroadcast(intent1);
Run Code Online (Sandbox Code Playgroud)

你可以在这里详细阅读