i trying gyroscope sensor result in android studio. display arrow ui indicting direction. wrote code there 2 problem.
- when start playing device not showing correct arrow
- how refresh value when user move phone.
public class navigationactivity extends actionbaractivity implements sensoreventlistener { private sensor gyroscope; private sensormanager msensormanager; private imageview go, right, left, back; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_navigation); go = (imageview) findviewbyid(r.id.nav_go); right = (imageview) findviewbyid(r.id.nav_right); left = (imageview) findviewbyid(r.id.nav_left); = (imageview) findviewbyid(r.id.nav_back); go.setvisibility(view.gone); right.setvisibility(view.gone); left.setvisibility(view.gone); back.setvisibility(view.gone); msensormanager = (sensormanager) getsystemservice(sensor_service); gyroscope = (sensor)msensormanager.getdefaultsensor(sensor.type_gyroscope);} @override protected void onresume() { super.onresume(); //register sensor update msensormanager.registerlistener(this, gyroscope, sensormanager.sensor_delay_ui);} }
this onsensorchanged: http://postimg.org/image/4my837rr9/ (on same code above)
ui: http://s24.postimg.org/6gfyy2qrp/stack.png
p.s
1.the default screen orientation "landscape"
2.the information build (azimuth, pitch, , roll) on according following:
values[0]: azimuth, rotation around z axis (0<=azimuth<360). 0 = north, 90 = east, 180 = south, 270 = west
values[1]: pitch, rotation around x axis (-180<=pitch<=180), positive values when z-axis moves toward y-axis.
values[2]: roll, rotation around y axis (-90<=roll<=90), positive values when z-axis moves toward x-axis.