-1

I am working on calling feature and i want an activity to be opened and the screen to wake up whenever there is an incoming call. I am able to start the activity but am not able to wake up the screen. I have tried as many solutions available here on Stackoverflow, still no luck.

I am providing the links of few of the solutions i have tried..

Turning on screen programmatically

Light up screen when notification received android

Can anyone help me out with how can I achieve this?

Kunal
  • 412
  • 5
  • 21

2 Answers2

0

Add this to activity you want to open when screen is locked:

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

}
amit srivastava
  • 743
  • 6
  • 25
0

Could you please provide a bit more information (or post the screen activity fragment ideally) from what i understand reading the 2 solutions you included you have not set the flags at all for the windowmanager :

window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

the full wake lock method is deprecated and it is likely to kill the activity

jkmog
  • 1