2015-05-08 33 views
0

我正在嘗試檢測旋轉而不是屏幕方向更改。getRotationMatrix始終爲false並且解決方案不起作用

我只在getRotationMatrix()上得到一個false。

我找到了一個解決方案here但它沒有爲我工作。

@Override 
public void onSensorChanged(SensorEvent event) { 
    // This method will be called when the accelerometer values are changing. 
    if (event == null || event.values.length == 0) throw new IllegalArgumentException(); 
    else { 
     // Handle the events for which we registered 
     switch (event.sensor.getType()) { 
      case Sensor.TYPE_ACCELEROMETER: 
       Log.i(TAG, "detected Accelerometer"); 
        mValuesAccel = event.values; 

       break; 

      case Sensor.TYPE_MAGNETIC_FIELD: 
       Log.i(TAG, "detected Magneticfield"); 
        mValuesMagnet = event.values; 

       break; 
     } 

     Log.i(TAG, ""+ SensorManager.getRotationMatrix(mRotationMatrix, null, mValuesAccel, mValuesMagnet)); 
     SensorManager.getOrientation(mRotationMatrix, mValuesOrientation); 

     mRotationListener.onChange(mValuesOrientation); 

    } 

} 

回答

2

檢查您的設備是否有指南針。 如果沒有指南針,那麼你的mValuesMagnet總是空的,結果getRotationMatrix返回false。

相關問題