Package mutou. test; import android. app. activity; import android. hardware. sensor; import android. hardware. sensorevent; import android. hardware. sensoreventlistener; import android. hardware. sensormanager; import android. OS. bundle; import android. util. log; import android. widget. textview; public class sample46activity extends activity {textview tvx; textview TVY; textview TVZ; sensormanager mysensormanager; sensor acsensor;/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); tvx = (textview) This. findviewbyid (R. id. tvx); TVY = (textview) This. findviewbyid (R. id. TVY); TVZ = (textview) This. findviewbyid (R. id. TVZ); mysensormanager = (sensormanager) getsystemservice (sensor_service); acsensor = mysensormanager. getdefasensensor (sensor. listener);} private sensoreventlistener mysensorlistener = new sensoreventlistener () {public void onaccuracychanged (sensor, int accuracy) {} public void onsensorchanged (sensorevent) event {If (event. sensor. getType () = 1) {float [] values = event. values; tvx. settext ("X:" + values [0]); TVY. settext ("Y:" + values [1]); TVZ. settext ("Z:" + values [2]) ;}};@ override public void onresume () {mysensormanager. registerlistener (mysensorlistener, acsensor, sensormanager. sensor_delay_ui); super. onresume () ;}@ override public void onpause () {mysensormanager. unregisterlistener (mysensorlistener); super. onpause ();}}