简体   繁体   中英

Windows Phone 8.1 Accelerometer detecting a shake

I having problems finding documentation or examples regarding the proper way to use the Accelerometer to trigger a Shake event. Seems like it should be easy, but all the examples are 8.0 which apparently are using Microsoft.Devices.Sensors;

Apparently you are supposed to use using Windows.Devices.Sensors; which you would think are the same, but things like Start() and Stop methods no longer exist. I was trying to use a Microsoft AccelerometerHelper class from Microsoft and it also uses the older namespace. The Shaken event in the Accelerometer class is only triggered on the tablets and not phones according to:

MSDN : here

Windows Phone 8: The accelerometer sensor does not raise the Shaken event on the Windows Phone 8 platform. If you add an event handler for the Shaken event in your Windows Phone 8 app, no error is raised, but the code in the event handler won't run.

如果您无法将代码移植到WP 8.1运行时,最后的选择还是另一种选择是将项目切换到Windows Phone 8 Silverlight甚至是8.1 Silverlight,所有代码都可以正常运行,我之前使用过AccelerometerHelper类并且面对相同问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM