Xamarin - device keep screen on

Roman Rusz 21 Reputation points
2021-03-10T15:02:41.677+00:00

Hello, according this: https://learn.microsoft.com/en-us/dotnet/api/xamarin.essentials.devicedisplay.keepscreenon?view=xamarin-essentials-watchos#Xamarin_Essentials_DeviceDisplay_KeepScreenOn

Can someone please explain me, how and where to use it on my "hello world" xamarin app for wearable Samsung Galaxy Watch?

Simply I need prevent go to sleep mode when you turn your wrisp (hand). If you are looking on app, app is visible. When you, let's say, walking, the app goes sleep (clock appear). I need to prevent this and have always on my app.

I found many tutorials, but every on android mobile app, not wearable xamarin.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Roman Rusz 21 Reputation points
    2021-03-11T13:07:25.91+00:00

    This is what helped me:

       `void MakeScreenOn(int value)
        {
            int ret = DevicePowerRequestLock(value, 0); // type : CPU:0, DisplayNormal:1, DisplayDim:2
        }
    
       void MakeScreenOff()
            {
                int ret = DevicePowerReleaseLock(1); 
            }
    
        [DllImport("libcapi-system-device.so.0", EntryPoint = "device_power_request_lock", CallingConvention = CallingConvention.Cdecl)]
        internal static extern int DevicePowerRequestLock(int type, int timeout_ms);
    
        [DllImport("libcapi-system-device.so.0", EntryPoint = "device_power_release_lock", CallingConvention = CallingConvention.Cdecl)]
        internal static extern int DevicePowerReleaseLock(int type);`
    
    0 comments No comments