1

Right now I am using 3 devices for testing: Samsung S7500, Galaxy Mexus, HTC explore. If the devices are active, then I am receiving push notification in all three devices. If it is in idle state(locked/sleep), then also I am receiving push notification in all three devices. But if it is offline when the push message has been send, the time I am getting online should receive all pending notifications as per the documentation. But in this case I am not receiving notification in all the devices. Specially in Galaxy Nexus, sometime I am receiving if it is in idle state and sometime not. Where I am getting wrong? Can anyone help me?

String posted to GCM server from Third party server(.Net) end: where "i" is the current time.

String postdata= "collapse_key=score_update"+i+"&time_to_live=2419200&delay_while_idle=1&data.message=‌​"+ message + "&data.time=" + System.DateTime.Now.ToString()
                    + "&registration_id=" + deviceToken + "";

Mentioned all required permissions in manifest as per documentation including Wakelock. This is my code for notiication in GCMIntentService class:

            int icon = R.drawable.notif;
        long when = System.currentTimeMillis();
            NotificationManager notificationManager =(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
        Notification notification = new Notification();
        Intent notificationIntent = new Intent(context, DemoActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, (int) when,
                notificationIntent,0);
           RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.notify);
        contentView.setImageViewResource(R.id.ImageViewpnotify, icon);
        contentView.setTextViewText(R.id.TextViewpnotify, message);
        notification.contentView = contentView;
        notification.contentIntent= intent;
        notification.icon = icon;   
        notification.flags |= Notification.FLAG_AUTO_CANCEL;       
            notification.defaults |= Notification.DEFAULT_SOUND;       
            notification.defaults |= Notification.DEFAULT_VIBRATE;      
        notification.ledARGB = 0xffff0000;
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
        notification.ledOnMS = 100; 
        notification.ledOffMS = 100;
        notificationManager.notify((int)when, notification);
Mark Nadig
  • 4,901
  • 4
  • 37
  • 46
ARIJIT
  • 515
  • 8
  • 22
  • why do you specify delay_while_idle=1 ? – Kiran Kumar Feb 14 '13 at 09:15
  • from docs, delay_while_idle : If included, indicates that the message should not be sent immediately if the device is idle. – Kiran Kumar Feb 14 '13 at 09:15
  • As per the documentation in http://developer.android.com/google/gcm/adv.html, it is given that delay_while_idle flag should be true if the device is idle. So, I have specify it to 1(true). If you can have tested, plz provide me the values – ARIJIT Feb 14 '13 at 09:22
  • "If the device is connected but idle, the message will still be delivered right away unless the delay_while_idle flag is set to true. " please specify "delay_while_idle" : false – Kiran Kumar Feb 14 '13 at 09:26
  • Also if you have seen, is it require to incremented the collapse_key. Because i have appended a incremental value "i" to the value – ARIJIT Feb 14 '13 at 09:36

1 Answers1

0

i know it is late to answer your question, but i had the same problem and i managed to solve it using the following link:

https://gist.github.com/mgartner/7092333

it is a bug in some devices where the service goes into idle state and stops receiving any notifications, the solution is by forcing it to restart every 5 min. also you can use the following link to help u in customizing your gcmreceiver:

http://code.google.com/p/gcm/source/browse/gcm-client/src/com/google/android/gcm/GCMBaseIntentService.java?r=8094cc6410b7dc2db452eb19cc9274fda1b2d6a2

user173488
  • 947
  • 1
  • 9
  • 20