I am looking into the method of monitoring accelerometer in the background.
We can get the sample for Windows Phone which implements it at MSDN.
According to the sample code, it requires the id of an accelerometer. However, there is no property which gets the device ID for WinRT.
var rs = await BackgroundExecutionManager.RequestAccessAsync();
if (rs != BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity
|| rs != BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity) return;
var btb = new BackgroundTaskBuilder() {
Name = TaskName,
TaskEntryPoint = TaskEntryPoint
};
btb.SetTrigger(trigger);
taskregist = btb.Register();
taskregist.Completed += new BackgroundTaskCompletedEventHandler(OnBackgroundTaskCompleted);
try {
var dres = await trigger.RequestAsync(); // Requires the accelerometer's device-id
switch (dres) {
case DeviceTriggerResult.Allowed:
break;
case DeviceTriggerResult.LowBattery:
break;
case DeviceTriggerResult.DeniedBySystem:
break;
default:
break;
}
} catch (InvalidOperationException) {
}
Can I observe an accelerometer's state in the background on WinRT devices?
Based on msdn,
DeviceUseTrigger
background task can access the sensors API only from within a Windows Runtime phone app, other winrt devices aren't supportedhere the list of what is supported
And finally here a basic example of consuming the accelerometer's data by handling the
ReadingChanged
event