I have IIS server and send Notification with GoogleCloudMessaging to phone. It takes about 10 minutes to receive the message on android device. It's huge time form my project. do you know how decrease the time ?
That is server C# code (Using 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();
And This Is my receiver,
public class GcmBroadcastReceiver extends 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);
}
}
The problem was that many wifi routers close connection to server and the device needs time to reconnect to Google server after wifi closes connection.
The solution is to send heartbeat packages every 3-4 minutes to have permanent connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With