1:項(xiàng)目中管理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:項(xiàng)目中管理nuget中添加vibrate plugin(xam.plugins.vibr)
(1)代碼(這個(gè)是震動功能),android注意填寫震動權(quán)限
var v = CrossVibrate.Current;
v.Vibration(500);
3:在1事件中判斷x,y候址,z軸的變化,變化達(dá)到自己規(guī)定的值就調(diào)用2中的代碼震動,至此完成