7

I have an Android app, instant messaging is one of the key features. For implementing the IM feature, we use our push server based on websocket.

For my app, I have a PushService, in this service, I establish a websocket connection which connects to the push server and receive push message.

The code works well when app in foreground (i.e.: works well while user plays with the app), but when the app doesn't in foreground, it stop receiving push messages after a while (about 1 minute). Same issue when user turns off screen.

I have set a repeat task with AlarmManager, which checks the websocket connection status, if it is not in connected status, then re-try to connect so as to back to normal to receive push messages.

This works well below Android M, for example on the Android 5 phones, it seldom misses push messages. But on Android M / Android N, it doesn't work as good as on Android 5.x. I can confirm the service itself is keep running , check from the 'Running services'.

I've noticed that starts from Android M, Android introduces Doze and Standby mode, not sure if they are related, if yes, how can I make the app continue to work again? On my phone the WeChat and Skype Android App work well, what's the mechanism behind it? I know FCM is the best solution, but I cannot use that for customers in China, so I need a workaround.

Edit: I had proposed to use a foreground service but PM doesn't like the notification tray always being shown in the status bar he wants to keep it clean.

Any advice will be appreciated!

LiuWenbin_NO.
  • 1,216
  • 1
  • 16
  • 25
  • Perhaps you need to register a foreground service. This previous question may help you out: https://stackoverflow.com/q/46780547/2012017 – Justin Heath Dec 04 '17 at 16:50
  • @JustinHeath, Thanks for your comment. I had proposed PM to use foreground service but got refused as he doesn't like a notification tray to keep the status bar clean. (I'll edit my question to avoid using foreground) – LiuWenbin_NO. Dec 05 '17 at 02:43
  • @LiuWenbin_NO. did you manage to find a solution for this? – Silvia H Mar 20 '18 at 13:45
  • @SilviaH, sorry no, I didn't find a solution to run on Android N / O. Switching to FCM but, the issue is still there. – LiuWenbin_NO. Mar 21 '18 at 03:05

1 Answers1

0

I don't know about WeChat or Skype communication, but i know the WhatsApp using you own service notification with the same tecnology of FCM. They using the Jaber server with implements the XMPP communication protocols

link

Community
  • 1
  • 1
Marco Aurelio
  • 505
  • 1
  • 4
  • 5