/**start the measurement of the gravity sensor*/ Public voidstart () {//Get the sensor managerSensormanager =(Sensormanager) Mcontext.getsystemservice (Context.sensor_service); if(Sensormanager! =NULL) {//obtaining a gravity sensorSensor =sensormanager.getdefaultsensor (Sensor.type_accelerometer); }//Register if(Sensor! =NULL) {Sensormanager.registerlistener ( This, sensor, sensormanager.sensor_delay_game); }}/**Stop Detection*/ Public voidStop () {Sensormanager.unregisterlistener ( This);}
1. Note If you want to repeat on a page to keep shaking, need you start () and stop () can only shake once (if you do not select Stop () he can only shake once, continue to shake will not shake) want to continue to shake must start the start () The method again stops () doing loops to repeat the shake, which is most important.
Considerations for Android shake-shake function