1

I am developing a little VoIP application and i need to stay connected to the server.

A was using push notifications at first (to wake up the device on incoming call), but android push notifications are not reliable due to very long heartbeat interval.

The second solution was to use a service with startForeground(). This method works, but leaves an icon in the notification bar (i know it's the way it should be, but please read on).

If i don't use startForeground() then service falls asleep as soon as te phone sleeps.

TLDR: Viber has a background service without startForeground() but it still works if the phone is sleeping and accepts incoming calls (even with push notifications disabled). How did they do that?

Arthur
  • 1,433
  • 1
  • 18
  • 35

2 Answers2

0

I suppose they hold a permanent TCP connection and use AlarmManager to wake up the phone with some interval (let's say 5 minutes) and keep the connection alive.

Check this question.

Community
  • 1
  • 1
  • So basically this answer led me to the right direction! Anyone interested, you can check the discussion in the link from this answer. – Arthur Aug 07 '14 at 07:22
  • But you get messages instantly, not after 5 minutes passed – user924 Aug 22 '19 at 08:29
0

Try using WakeLock to keep device always awake. But it may cause battery drain.

Fedor
  • 43,261
  • 10
  • 79
  • 89