0

I've already read a lot about this topic on SO. I'm trying to write SIP Client, which of course should accept incoming calls when the device is sleeping. The first thing I've tried was to use these flags in my onCreate method:

Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

And my devices (different models of phones and different API Levels) woke up only when they were plugged in to PC with USB cable or were in charging process.
When phones were unplugged there were no impact of flags. Then I found that one guy has already asked a similar question on SO: Android - Wake Up and Unlock Device Nobody replied to him and after some time he had found answer on his question and posted it. The answer was to use PowerManager class. His answer helped me a lot, but documentation of PowerManager says "Device battery life will be significantly affected by the use of this API". I felt it on myself. My application began to use too much energy of battery. I compared my app with WhatsApp and saw gigantic difference in battery energy using.
So, is there any other way to wake up device when it sleeps or
does anybody know how this process works in WhatsApp, Skype and other apps which receives incoming calls and saves battery life?

1 Answers1

0

You can use-

android:showOnLockScreen="true"

in your manifest file and in your activity which you want that should appear on screen lock.

Shivam Oberoi
  • 1,447
  • 1
  • 9
  • 18
  • I think it is the same as window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); But I checked it and saw no difference. – Zaur Tregulov Dec 08 '17 at 08:41