/// <summary> /// Initializes activity monitor /// </summary> public async Task Initialize() { if (ActivityMonitorProperty == null) { if (await MapPage._instanceMap.CallSensorcoreApiAsync(async() => { ActivityMonitorProperty = await ActivityMonitor.GetDefaultAsync(); })) { Debug.WriteLine("ActivityMonitorSimulator initialized."); } if (ActivityMonitorProperty != null) { // Set activity observer ActivityMonitorProperty.ReadingChanged += activityMonitor_ReadingChanged; ActivityMonitorProperty.Enabled = true; // read current activity ActivityMonitorReading reading = null; if (await MapPage._instanceMap.CallSensorcoreApiAsync(async() => { reading = await ActivityMonitorProperty.GetCurrentReadingAsync(); })) { if (reading != null) { this.ActivityEnum = reading.Mode; } } } else { // nothing to do if we cannot use the API // in a real app do make an effort to make the user experience better return; } // Must call DeactivateAsync() when the application goes to background Window.Current.VisibilityChanged += async(sender, args) => { if (_activityMonitor != null) { await MapPage._instanceMap.CallSensorcoreApiAsync(async() => { if (!args.Visible) { await _activityMonitor.DeactivateAsync(); } else { await _activityMonitor.ActivateAsync(); } }); } }; } }