Android推送通知(慢)

时间:2014-03-21 18:26:23

标签: android performance time notifications push-notification

我有IIS服务器并通过GoogleCloudMessaging发送通知给手机。在Android设备上接收消息大约需要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();

这是我的接收者,

公共类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);

}

}

1 个答案:

答案 0 :(得分:4)

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

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

Pushy旨在通过以5分钟的心跳间隔实现其自己的后台MQTT连接来解决此问题,以避免路由器和蜂窝运营商终止连接。