我有一个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();
这是我的接收器:
公共类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);
}
}