question

RomanRusz-7579 avatar image
0 Votes"
RomanRusz-7579 asked ·

Xamarin - device keep screen on

Hello, according this: https://docs.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.

dotnet-xamarinformsdotnet-xamarinforms-xamldotnet-xamarinessentials
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RomanRusz-7579 avatar image
0 Votes"
RomanRusz-7579 answered ·

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);`

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.