0

Imagine that we have the SIP stack Voip Android application, and we want to receive message, and calls in sleep mode.

By using ADB we put devices in IDLE states, and haven't any source for receiving incoming message from signaling. Neither AlarmClock, nor Service don't suite for this task! So there are no ways, to handle action in IDLE state, besides GCM! Or I'm wrong?

I explored all documentation about battery optimizing and sleep states. Google just said about Voip application interesting thing:

No, can not use GCM because of technical dependency on another messaging service or Doze and App Standby break the core function of the app.

So, what is that means? We don't need to use GCM, but always make device active, for this issues - it's ok? I just want to know, what is correct way, for listening action in sleep states in VoiP Application!

Thanks!

GensaGames
  • 5,538
  • 4
  • 24
  • 53

1 Answers1

1

The solution to always be able to receive incoming messages is the following:

Create a service which is always running in the background and run your sipstack from there.

Lock the WiFi because devices can be configured to switch off the WiFi when goes to idle:

private WifiLock wifiLock = null;
ContentResolver ctntResolver = appcontext.getContentResolver();
int set = android.provider.Settings.Global.WIFI_SLEEP_POLICY_NEVER;
android.provider.Settings.System.putInt(ctntResolver, android.provider.Settings.Global.WIFI_SLEEP_POLICY, set);

Prevent the CPU for going offline:

private WakeLock screenandcpuLockalways = null;
private PowerManager powermanager = null;
public void SetScreenAndCPULockAlways(boolean on)
{               
    if (on)
    {
        if (screenandcpuLockalways != null && screenandcpuLockalways.isHeld())
        {

        }
        else
        {
            if (powermanager == null)
            {
                powermanager = (PowerManager) appcontext.getSystemService(Context.POWER_SERVICE);
            }

            screenandcpuLockalways = powermanager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,"MyApp");
            screenandcpuLockalways.acquire();
        }
    }
    else
    {
        if (screenandcpuLockalways != null && screenandcpuLockalways.isHeld())
        {               
            screenandcpuLockalways.release();
        }
    }               
}
Istvan
  • 1,591
  • 1
  • 13
  • 19