Android how to detect if phone is turned around -
this code detecting if phone turned around or not
private sensormanager sensormanager; private int orientationlim = 165; @override public void onsensorchanged(sensorevent event) { if (event.sensor.gettype() == sensor.type_orientation) { // if shake stop enabled boolean turnaroundtostop = utils.getbooleanfromproperties(this, properties.sp_cb_turn_around_to_stop); if (turnaroundtostop) { float value = math.abs(event.values[1]); if (value > orientationlim && !stopped) { // down stopped = true; } else { // stopped = false; } } } }
but problem stopped
variable set true phone not turned around little.
how can modify code executed when phone relay turned around.
float pitch = values[2]; if (pitch <= 45 && pitch >= -45) { // vertical } else if (pitch < -45) { // right side } else if (pitch > 45) { // left side }
take here on topic:
http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/
Comments
Post a Comment