使用加速度计时未经授权的访问异常

时间:2014-11-07 14:57:25

标签: c# windows-phone-8

每次用户摇动Windows电话设备时,我都尝试在页面之间导航,但每次更改轴时,都会显示未经授权的访问异常

    public Welcome_2()
    {
        InitializeComponent();
            Accelerometer acc = new Accelerometer();
            acc.TimeBetweenUpdates = TimeSpan.FromMilliseconds(5);
            acc.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(accEventHandler);
            acc.Start();
    }
    private void accEventHandler(object sender, SensorReadingEventArgs<AccelerometerReading> e)
    {
        Vector3 accelReading = new Vector3();
        accelReading.X = (float)e.SensorReading.Acceleration.X;
        accelReading.Y = (float)e.SensorReading.Acceleration.Y;
        accelReading.Z = (float)e.SensorReading.Acceleration.Z;
        if (accelReading.X > 0 || accelReading.X < 0)
        {

                NavigationService.Navigate(new Uri("/Get_Insert.xaml", UriKind.Relative));

        }

    }

1 个答案:

答案 0 :(得分:0)

要使用传感器(加速度计),请将Microsoft.Devices.Sensors和Microsoft.Xna.Framework引用添加到项目中。 还要确保在项目的“属性”文件夹下的应用清单文件的功能中选中了ID_CAP_SENSORS功能。