2014-09-05 1 views
0

나는 이것에 관한 실이 있다는 것을 알고 있으며, 나는 며칠 동안 그것을 읽었습니다.Android Sensor Upright Rotation

문제가 더 구체적이라고 생각합니다. 나는 장치를 y 축을 중심으로 회전 시키려고 노력하고있다. 내가 올바른 해요 경우

이,이

나는 응용 프로그램을 실행 방위각

라고, 그것은 디버그 로깅 값 [0] 값을 후 로그 캣에 0.0를 반환 [1], & 값 [2]

코드 :

mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); 
     accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); 
     magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); 

     SensorEventListener SEL = new SensorEventListener() { 
      @Override 
      public void onSensorChanged(SensorEvent event) { 

       mSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic); 

       mSensorManager.getOrientation(rotationMatrix, values); 

       accy = values[0]; 

       System.out.println(accy); 
      } 

      @Override 
      public void onAccuracyChanged(Sensor sensor, int accuracy) { 

      } 
     }; 

     int rate = SensorManager.SENSOR_DELAY_GAME; 
     mSensorManager.registerListener(SEL, accelerometer, rate); 
     mSensorManager.registerListener(SEL, magnetometer, rate); 

로그 캣 : 위의 코드에서

09-05 17:34:02.622 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.642 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.642 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.662 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.662 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.682 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.682 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.702 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.702 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.722 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.722 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.742 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.742 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.762 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.762 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.782 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.782 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.802 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 
09-05 17:34:02.802 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0 

답변

1

매개 변수 gravitymSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic);geomagnetic 아마 zero array 및 따라서 귀하의 accy 항상 zero

+0

괜찮 있습니다. 자, 그건 분명해 보입니다. 나는이 기능을 충분히 이해하지 못해서 약간의 연구를 아프게한다. 고맙습니다. – ahew

+0

http://stackoverflow.com/questions/17979238/android-getorientation-azimuth-gets-polluted-when-phone-is-tilted/17981374#17981374 –

+0

완벽한보세요. 이것은 내가 찾으려고 노력한 것입니다. – ahew