miyahira
asked on
How to turn on screen programmatically in Android?
I have developed an App that loads automatically when smartphone receives an SMS message.
Problem is that when screen's phone is off or in "black" mode, App doesn't load when SMS arrives. I need that my app turns screen on programmatically. Is that possible? I found several past solutions but no one has worked.
I tried:
I've been advised that this code could do the trick:
However, Android Studio shows me error:
Is there any import or setting that I should do?
Problem is that when screen's phone is off or in "black" mode, App doesn't load when SMS arrives. I need that my app turns screen on programmatically. Is that possible? I found several past solutions but no one has worked.
I tried:
WindowManager.LayoutParams params =
getWindow().getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);
And tried:super.onCreate(savedInstanceState);
setContentView(R.layout.my_main_activity);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
And no success.I've been advised that this code could do the trick:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
However, Android Studio shows me error:
Cannot resolve symbol 'FLAG_SHOW_WHEN_LOCKED'
Is there any import or setting that I should do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.