Windows 8 检测windows 8设备中的移动或抖动

Windows 8 检测windows 8设备中的移动或抖动,windows-8,windows-store-apps,accelerometer,tablet,Windows 8,Windows Store Apps,Accelerometer,Tablet,在Windows 8 Metro中-鉴于它打算在平板电脑上使用,是否可以检测设备是否受到震动或移动 这篇文章似乎并没有涵盖设备的移动 如果这是可能的,那么是否有任何在线教程或代码片段可用?我想您正在寻找 使用Windows.UI.Core; 使用Windows.Devices.Sensors; 名称空间加速度计 { 部分类空白页 { //传感器和调度器变量 专用加速计(加速计);; //此事件处理程序将当前加速计读数写入 //应用程序主页上的三个加速文本块。 私有无效读取已更改(对象发送器、加速

在Windows 8 Metro中-鉴于它打算在平板电脑上使用,是否可以检测设备是否受到震动或移动

这篇文章似乎并没有涵盖设备的移动


如果这是可能的,那么是否有任何在线教程或代码片段可用?

我想您正在寻找

使用Windows.UI.Core;
使用Windows.Devices.Sensors;
名称空间加速度计
{
部分类空白页
{
//传感器和调度器变量
专用加速计(加速计);;
//此事件处理程序将当前加速计读数写入
//应用程序主页上的三个加速文本块。
私有无效读取已更改(对象发送器、加速计READINGCHANGDEVENTARGS e)
{
Dispatcher.InvokeAsync(CoreDispatcherPriority.Normal,(s,a)=>
{
AccelerometerReading reading=(a.Context作为AccelerometerReadingChangedEventArgs)。reading;
txtXAxis.Text=String.Format(“{0,5:0.00}”,reading.AccelerationX);
txtYAxis.Text=String.Format(“{0,5:0.00}”,reading.AccelerationY);
Text=String.Format(“{0,5:0.00}”,reading.AccelerationZ);
},本,e);
}
公共空白页()
{
初始化组件();
_Accelerator=Accelerator.GetDefault();
如果(_加速度计!=null)
{
//建立报告间隔
uint最小报告间隔=_加速计最小报告间隔;
uint reportInterval=minReportInterval>16?minReportInterval:16;
_Accelerator.ReportInterval=报告间隔;
//为读取已更改事件分配事件处理程序
_Accelerator.ReadingChanged+=新类型的手持设备(ReadingChanged);
}
}
}
}

请注意,加速计上有一个特定的震动事件,请参阅。不适用于Windows Phone 8设备:'加速计传感器不会在Windows Phone 8平台上引发震动事件。如果在Windows Phone 8应用程序中为震动事件添加事件处理程序,则不会引发任何错误,但事件处理程序中的代码不会运行。“@Filimindji此问题明确与Windows 8有关,而不是与Windows Phone有关8@mydogsibox:我错了。
using Windows.UI.Core;
using Windows.Devices.Sensors;

namespace AccelerometerCS
{

    partial class BlankPage
    {
        // Sensor and dispatcher variables
        private Accelerometer _accelerometer;

        // This event handler writes the current accelerometer reading to 
        // the three acceleration text blocks on the app's main page.

        private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
        {
            Dispatcher.InvokeAsync(CoreDispatcherPriority.Normal, (s, a) =>
            {
                AccelerometerReading reading = (a.Context as AccelerometerReadingChangedEventArgs).Reading;
                txtXAxis.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
                txtYAxis.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
                txtZAxis.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);

            }, this, e);
        }

        public BlankPage()
        {
            InitializeComponent();
            _accelerometer = Accelerometer.GetDefault();

            if (_accelerometer != null)
            {
                // Establish the report interval
                uint minReportInterval = _accelerometer.MinimumReportInterval;
                uint reportInterval = minReportInterval > 16 ? minReportInterval : 16;
                _accelerometer.ReportInterval = reportInterval;

                // Assign an event handler for the reading-changed event
                _accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
            }

        }
    }
}