Hello,
Is it possible to adjust the screen dimmer and the lock screen on Android?
Yes, you can open your Activity1.cs
, then override the OnAttachedToWindow
method. Then create a method, set the KEEP_SCREEN_ON flag and DismissKeyguard flag in WIndow. And set TurnScreenOn and ShowWhenLocked to true. I test it in my devices, it will not lock the screen when application running.
You can refer to the following code.
public override void OnAttachedToWindow()
{
base.OnAttachedToWindow();
DisabletheLockScreen();
}
private void DisabletheLockScreen()
{
Window.AddFlags(WindowManagerFlags.DismissKeyguard |WindowManagerFlags.KeepScreenOn);
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
SetTurnScreenOn(true);
SetShowWhenLocked(true);
}
else
{
Window.AddFlags(WindowManagerFlags.ShowWhenLocked | WindowManagerFlags.KeepScreenOn);
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.