Android 推送通知(慢)

Mis*_*pov 5 performance time notifications android push-notification

我有 IIS 服务器并使用 GoogleCloudMessaging 向手机发送通知。在安卓设备上接收消息大约需要 10 分钟。我的项目时间很长。你知道如何减少时间吗?

那是服务器 C# 代码(使用 PushSharp)

var push = new PushBroker();

        //Wire up the events for all the services that the broker registers
        /*NotificationSent s = new NotificationSent()
        push.OnNotificationSent += "NotificationSent";
        push.OnChannelException += "ChannelException";
        push.OnServiceException += "ServiceException";
        push.OnNotificationFailed += "NotificationFailed";
        push.OnDeviceSubscriptionExpired += "DeviceSubscriptionExpired";
        push.OnDeviceSubscriptionChanged += "DeviceSubscriptionChanged";
        push.OnChannelCreated += "ChannelCreated";
        push.OnChannelDestroyed += "ChannelDestroyed";
        */

        push.RegisterGcmService(new GcmPushChannelSettings("MY API KEY"));

        push.QueueNotification(new GcmNotification().
            ForDeviceRegistrationId("PHONE REGISTRATION ID")
                              .WithJson(@"{""alert"":""Name !"",""badge"":7,""sound"":""sound.caf""}"));


        //Stop and wait for the queues to drains
        push.StopAllServices();
Run Code Online (Sandbox Code Playgroud)

这是我的接收器,

公共类 GcmBroadcastReceiver 扩展 WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
     // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(),
            GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);

}
Run Code Online (Sandbox Code Playgroud)

}

Mis*_*pov 4

问题是许多 wifi 路由器关闭了与服务器的连接,并且在 wifi 关闭连接后设备需要时间重新连接到 Google 服务器。

解决方案是每隔3-4分钟发送一次心跳包,以实现永久连接。