Xamarin.Essentials Screen Lock

Pre-release NuGet

The ScreenLock class can request to keep the screen from falling asleep when the application is running.

Using ScreenLock

Add a reference to Xamarin.Essentials in your class:

using Xamarin.Essentials;

The screen lock functionality works by calling the RequestActive and RequestRelease methods to request the screen from turning off.

public class ScreenLockTest
{
    public void ToggleScreenLock()
    {
        if (ScreenLock.IsActive)
            ScreenLock.RequestActive();
        else
            ScreenLock.RequestRelease();
    }
}

API