1:项目中管理nuget中添加device motion plugin(xam.plugin.devicemotion)
(1)代码(得到传感器的变化值,x,y,z轴变化值)
CrossDeviceMotion.Current.Start(MotionSensorType.Accelerometer);
CrossDeviceMotion.Current.SensorValueChanged += (s, a) =>
{
switch (a.SensorType)
{
case MotionSensorType.Accelerometer:
Debug.WriteLine("A: {0},{1},{2}", ((MotionVector)a.Value).X, ((MotionVector)a.Value).Y, ((MotionVector)a.Value).Z);
break;
}
};
2:项目中管理nuget中添加vibrate plugin(xam.plugins.vibr)
(1)代码(这个是震动功能),android注意填写震动权限
var v = CrossVibrate.Current;
v.Vibration(500);
3:在1事件中判断x,y,z轴的变化,变化达到自己规定的值就调用2中的代码震动,至此完成