对不起每个人,作为主题,我没有看到我的aAngle和bAngle的变化。
@Override
public void onCreate(Bundle savedInstanceState) {
sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
}
public void onResume()
{
super.onResume();
if (aAngleList.size() <= 50){
List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
if (sensors.size() > 0 && sensors.size() <= 10) {
sensorManager.registerListener(this, sensors.get(0), SensorManager.SENSOR_DELAY_FASTEST);
}
}
else {
sensorManager.unregisterListener(this);
for(int i = 0; i < aAngleList.size(); i++){
aAngleTotal += aAngleList.get(i);
bAngleTotal += bAngleList.get(i);
aAngleAverage = aAngleTotal / aAngleList.size();
bAngleAverage = bAngleTotal / aAngleList.size();
}
calculatePosB(aAngleAverage, bAngleAverage);
calculatePosC(aAngleAverage, bAngleAverage);
calculatePosD(aAngleAverage, bAngleAverage);
Log.d("ForDebug", Double.toString(bAngleAverage));
}
}
@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
aAngle = -(Math.toDegrees(Math.acos(event.values[0]/Math.pow(Math.pow(event.values[0],2)+Math.pow(event.values[1],2)+Math.pow(event.values[2],2), 0.5))) - 90);
bAngle = -(Math.toDegrees(Math.acos(event.values[1]/Math.pow(Math.pow(event.values[0],2)+Math.pow(event.values[1],2)+Math.pow(event.values[2],2), 0.5))) - 90);
aAngleList.add(aAngle);
bAngleList.add(bAngle);
)
我在onCreate中有我的sensormanager注册,并在onPause中取消注册,但我什么都没得到。看来我的手机没有拿到传感器?
此外,logcat没有显示Fordebug。 这是否意味着我无法获得平均值,因为我的应用程序无法获取代码来获取它?