车载的侧翻算法根据上面的公式实现,而碰撞时根据三个方向的加速度的值
主要利用了传感器的onSensorChanged来实现
packagecom
leadcore
packet;importjava
*;importandroid
content
Context;importandroid
hardware
Sensor;importandroid
hardware
SensorEvent;importandroid
hardware
SensorEventListener;importandroid
hardware
SensorManager;importjava
Math;importandroid
Log;publicclassGSensorService{privatestaticfinalStringTAG="GSensorService";privateContextmContext=null;privatebooleanmIsRolloverWarning=false;privatebooleanmIsCrashWarning=false;publicGSensorService(Contextcontext){mContext=context;}privatefinalSensorEventListenermSensorListener=newSensorEventListener(){@OverridepublicvoidonSensorChanged(SensorEventevent){if(Sensor
TYPE_ACCELEROMETER==event
sensor
getType()){floatxAxis=event
values[0];floatyAxis=event
values[1];floatzAx