/// <summary> /// Static method to get the default activity sensor present in the system. /// </summary> public static async Task <IActivitySensor> GetDefaultAsync() { IActivitySensor sensor = null; try { // Check if there is an activity sensor in the system ActivitySensor activitySensor = await ActivitySensor.GetDefaultAsync(); // If there is one then create OSActivitySensor. if (activitySensor != null) { sensor = new OSActivitySensor(activitySensor); } } catch (System.UnauthorizedAccessException) { // If there is an activity sensor but the user has disabled motion data // then check if the user wants to open settngs and enable motion data. MessageDialog dialog = new MessageDialog("Motion access has been disabled in system settings. Do you want to open settings now?", "Information"); dialog.Commands.Add(new UICommand("Yes", async cmd => await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-motion")))); dialog.Commands.Add(new UICommand("No")); await dialog.ShowAsync(); new System.Threading.ManualResetEvent(false).WaitOne(500); return(null); } // If the OS activity sensor is not present then create the LumiaActivitySensor. // This will use ActivityMonitor from SensorCore. if (sensor == null) { // Check if all the required settings have been configured correctly await LumiaActivitySensor.ValidateSettingsAsync(); sensor = new LumiaActivitySensor(); } return(sensor); }
/// <summary> /// Static method to get the default activity sensor present in the system. /// </summary> public static async Task<IActivitySensor> GetDefaultAsync() { IActivitySensor sensor = null; try { // Check if there is an activity sensor in the system ActivitySensor activitySensor = await ActivitySensor.GetDefaultAsync(); // If there is one then create OSActivitySensor. if (activitySensor != null) { sensor = new OSActivitySensor(activitySensor); } } catch (System.UnauthorizedAccessException) { // If there is an activity sensor but the user has disabled motion data // then check if the user wants to open settngs and enable motion data. MessageDialog dialog = new MessageDialog("Motion access has been disabled in system settings. Do you want to open settings now?", "Information"); dialog.Commands.Add(new UICommand("Yes", async cmd => await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-motion")))); dialog.Commands.Add(new UICommand("No")); await dialog.ShowAsync(); new System.Threading.ManualResetEvent(false).WaitOne(500); return null; } // If the OS activity sensor is not present then create the LumiaActivitySensor. // This will use ActivityMonitor from SensorCore. if (sensor == null) { // Check if all the required settings have been configured correctly await LumiaActivitySensor.ValidateSettingsAsync(); sensor = new LumiaActivitySensor(); } return sensor; }