android - Recognize Device Position In User's Hand -


i need recognize how user hold device. tried use in couple accelerometer , magnetometer in way:

public void onsensorchanged(sensorevent event) {          switch(event.sensor.gettype()) {              case sensor.type_accelerometer:                 mgravity = event.values.clone();                 log.d("sensor","accel");                 break;             case sensor.type_magnetic_field:                 log.d("sensor","magnet");                 mmagnetic = event.values.clone();                 break;             default:                 log.d("sensor","default");          }         if(mgravity != null && mmagnetic != null) {             //float[] temp = new float[9];             float[] r = new float[9];             //load rotation matrix r             sensormanager.getrotationmatrix(r, null,                     mgravity, mmagnetic);              //return orientation values             float[] values = new float[3];             sensormanager.getorientation(r, values);               //convert degrees             (int i=0; < values.length; i++) {                 double degrees = (values[i] * 180) / math.pi;                 values[i] = degrees.floatvalue();             }          }         if (mvaluesorientation[0]!=0 || mvaluesorientation[1]!=0 || mvaluesorientation[2]!=0 ){             logorientation();         }     }      }; 

but have problem:

  • in same position obtain similar values. values different.

how can solve?


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -