This post will give you an overview on how to identify the sensors supported on your Windows Phone. As a developer when you are developing for Windows Phone – and your application would need to interact with certain sensors in windows phone to achieve a certain functionality, you would need to verify whether the sensors are supported in targeted devices.
Windows Phone 8 platform has support for the following sensors
- Motion sensor
- Accelerometer
- Compass
- Gyroscope
You can access these API’s through the below namespace:
Microsoft.Devices.Sensors
You can check for any of the sensor support through “IsSupported” boolean property of the class
- Motion sensor [ Microsoft.Devices.Sensors.Motion ]
- Accelerometer [ Microsoft.Devices.Sensors.Accelerometer ]
- Compass [ Microsoft.Devices.Sensors.Compass ]
- Gyroscope [ Microsoft.Devices.Sensors.Gyroscope ]
Here is the sample code block:
public static string GetSensors()
{
StringBuilder sensorsList = new StringBuilder();
if (Microsoft.Devices.Sensors.Gyroscope.IsSupported)
{
sensorsList.Append("Gyroscope, ");
}
if (Microsoft.Devices.Sensors.Compass.IsSupported)
{
sensorsList.Append("Compass, ");
}
if (Microsoft.Devices.Sensors.Accelerometer.IsSupported)
{
sensorsList.Append("Accelerometer, ");
}
if (Microsoft.Devices.Sensors.Motion.IsSupported)
{
sensorsList.Append("Motion,");
}
return sensorsList.ToString();
}
Note: Only Accelerometer is supported in Windows Phone 8 emulator. To test remaining capabilities, you would need to deploy the application on a real Windows Phone device.
Discover more from Code, Cloud & Context
Subscribe to get the latest posts sent to your email.