我想寫一個測試傳感器的應用程序,由我的Nexus S.如何獲取重力感應信息?
好吧,我寫這個來顯示通過列表視圖的傳感器列表。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//get all sensors
sensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
setContentView(R.layout.main);
sensorListView = (ListView) findViewById(R.id.sensor_listview);
sensorListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
showSensorInfo(sensors.get(position).getType());
}
});
//set an empty adapter for ListView
sensorNames = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1);
for (Sensor s : sensors) {
sensorNames.add(s.getName());
Log.i("sensor", s.getName());
}
sensorListView.setAdapter(sensorNames);
}
我看到這個〜
有一個叫做傳感器「重力感應」,
我的問題是,有傳感器,常數:
Sensor.TYPE_ACCELEROMETER
Sensor.TYPE_GYROSCOPE
Sensor.TYPE_LIGHT .. 。
等等。但我無法找到一個名爲「Sensor.TYPE_GRAVITY」恆
哪裏是重力感應距離= .. =一個? (我是一個真正的新手〜)
OP可能意味着Sensor.TYPE_GRAVITY是一種虛擬傳感器,它不僅僅是加速度計,而且還包括陀螺儀和指南針,可以產生更加準確和響應的結果。 – 2012-01-13 13:10:46