Reputation: 176
I want to be able to detect when the user changes the time in the Windows settings menu (timezone changes and auto-changes may be helpful to detect too). On application startup, I am currently checking an NTP server to check if the user's system time is correct. However, I need to be able to recheck if anything changes.
I am able to look out for this on Android using a Broadcast receiver that looks for: https://developer.android.com/reference/android/content/Intent#ACTION_TIME_CHANGED
On iOS, I was able to use: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622992-applicationsignificanttimechange
I'm using Xamarin.Forms. I was able to use Xamarin.Android + Xamarin.iOS code to implement the solution for those platforms. I am looking for a native UWP/WinUI solution to listen out for a similar user action.
I've been able to find some old .NET code that would apply to Win32 or .NET Framework which is no good: https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.systemevents.timechanged?redirectedfrom=MSDN&view=dotnet-plat-ext-6.0
I can see some modern APIs that can be used for detecting time zone changes https://learn.microsoft.com/en-us/uwp/api/windows.system.timezonesettings?view=winrt-22621 But that doesn't cover the user going and manually changing the date/time.
Or running background tasks at a fixed rate to check for the date time but this seems inefficient: https://learn.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.Background.TimeTrigger?redirectedfrom=MSDN&view=winrt-22621 It would be much better if the system broadcast an event and I could listen for that.
What is the best method to solve this problem?
Upvotes: 0
Views: 553
Reputation: 8681
UWP doesn't have an API that could detect the system time change directly. UWP could only detect the TimeZone change using the SystemTrigger.TimeZoneChange in the background task. The SystemEvents.TimeChanged event you found should be the way to detect the time change.
Upvotes: 0