i'm trying to write an app for testing sensors by my Nexus S.
well , i wrote this to show the sensors lists through a listview.
@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 on开发者_JS百科ItemClick(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);
}
i saw this ~
there is a sensor called 「Gravity Sensor」,
my question is , there are sensors CONSTANT such as :
Sensor.TYPE_ACCELEROMETER
Sensor.TYPE_GYROSCOPE
Sensor.TYPE_LIGHT .. .
and so on .But i couldn't find a CONSTANT called 「Sensor.TYPE_GRAVITY」
where is the Gravity Sensor from =..=a?? ( i'm a really newbie~ )
The gravity is measured by the accelerometer but you can look up the gravity constant (approximately 9.8m/s^2.) The method to get an accurate constant is SensorManager.STANDARD_GRAVITY You can look up the full use on http://developer.android.com/reference/android/hardware/SensorManager.html#STANDARD_GRAVITY
TYPE_GRAVITY
exists: http://developer.android.com/reference/android/hardware/SensorEvent.html
but its only available from Android 2.3 onwards. so check that in your app.
精彩评论