I want to disable auto-lock when my app is open. How can I do that?
We can achieve it by using Xamarin.Essentials
plugin. Install it on solution level(While installing select include prerelease checkbox).
In your MainPage
write this code
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
ToggleScreenLock();
}
public void ToggleScreenLock()
{
if (!ScreenLock.IsActive)
ScreenLock.RequestActive();
else
ScreenLock.RequestRelease();
}
}
In Android project MainActivity
add this line
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
before calling LoadApplication(new App());
. For more information visit Microsoft docs.
This is working throughout the app. To install plugin refer below screenshot -