Push notifications handling

258 views
Skip to first unread message

Oscar Corredor

unread,
Sep 26, 2014, 3:48:37 PM9/26/14
to codenameone...@googlegroups.com
Hey guys,

I have a question, is there a special way I have to handle push notifications when:

a) On iOS and Android: the device is locked, a push comes in and the user unlocks the device with the swipe to unlock instead of clicking on the notification (the app seems to not be passing through the push() method)
b) On iOS and Android: the app hasn't been started and a push comes in (the app seems to not be going through the push() method).
c) on Android, when you let the app sitaround for a while, it enters a sort of inactivity mode in which the  app simply won't receive any push notifications until you enter the app once again. I read somewhere that you could control this with something called a "heartbeat" in Android, which is the frequency in which the device signals GCM servers that it is active, but maybe you know a bit more about this or how to properly increment the heartbeat frequency.


Thanks.

Shai Almog

unread,
Sep 27, 2014, 12:01:59 PM9/27/14
to codenameone...@googlegroups.com
Hi,
a. this should arrive AFAIK, how do you determine this didn't arrive?
b. Was the app invoked for the first time to invoke register?
c. I don't think you need to do anything about this but Chen is a bigger GCM expert than I am so I'll deffer this to him.

Chen Fishbein

unread,
Sep 27, 2014, 12:19:58 PM9/27/14
to codenameone...@googlegroups.com
Hi,
From what I understands, it will receive the push, but you might experience long delays after a few minutes of inactivity in the app.
If your app is counting on a short delays push communications there are a few workarounds you can try.
1)Send a silent push from your server every couple of minutes to the currently active users.
2)I read somewhere that this might help: (not sure about this haven't tried it myself)
add this to your app (use Native interface to include this):
context.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
context.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));

Oscar Corredor

unread,
Sep 29, 2014, 9:50:41 AM9/29/14
to codenameone...@googlegroups.com
Hey guys,

thanks for your response. I'll implement the heartbeat and tell you how that goes, but regarding the first 2 points on my list I still have some questions.

I can determine the push notfication does in fact arrive because I can see it in the notification bar, but from what I can understand, it should execute the code once the app has been unlocked or launched depending on the case. I connect the corresponding devices to their consoles (Logcat or the console on my Mac) and I don't see the corresponding output for the push notifications when the app is either unlocked or launched.

This means the app is correctly registered for push notifications. Regarding the case when the push notification arrives when the app isn't open, it's not only a case of the first time launch but when the app was used, then closed (my tests were closing it by swiping it away from the recently used apps on Android and iOS).


Thanks.

Shai Almog

unread,
Sep 29, 2014, 9:28:31 PM9/29/14
to codenameone...@googlegroups.com
Hi,
how are you checking the logcat? Notice that system.out won't print there, only Log.p will print to console.

Oscar Corredor

unread,
Sep 30, 2014, 3:43:48 PM9/30/14
to codenameone...@googlegroups.com
Hey Shai,

I'm using Log.p and there is no problem with this. When tpush notifications come in the push information is shown on console perfectly. But on this two cases it doesn't appear to go through the push() method.



El viernes, 26 de septiembre de 2014 14:48:37 UTC-5, Oscar Corredor escribió:

Shai Almog

unread,
Sep 30, 2014, 11:58:56 PM9/30/14
to codenameone...@googlegroups.com
Hi,
I'll have to look into that its possible that this is how this works natively for iOS.
Reply all
Reply to author
Forward
0 new messages