gpt4 book ai didi

Android 推送通知(慢)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:09:04 24 4
gpt4 key购买 nike

我有 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();

这是我的接收器,

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

}

最佳答案

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

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

关于Android 推送通知(慢),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22566715/

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