Android Push notification (slow)

10,992

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.

Pushy aims to solve this by implementing its own background MQTT connection with a heartbeat interval of 5 minutes to avoid the connection from being terminated by routers and cellular carriers.

Share:
10,992
Misha Akopov
Author by

Misha Akopov

Ranked #1 in android for Top-Users of Georgia LinkedIn profile

Updated on June 04, 2022

Comments

  • Misha Akopov
    Misha Akopov almost 2 years

    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);
    
    }
    

    }