android - How to receive all sensors list (include not supported) -
i want enumerate all sensors supported google , verify if device support or not (include step counter, game rotation vector, geomagnetic rotation vector, significant motion, etc.)
i use sensor.type_all
receive sensors, code below:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_enumarte_sensors); sensormanager sensormanager; textview tvavailablesensors; sensormanager = (sensormanager) getsystemservice(sensor_service); list<sensor> sensors = sensormanager.getsensorlist(sensor.type_all); tvavailablesensors = (textview) findviewbyid(r.id.tv_availablesensors); tvavailablesensors.settext("sensors status:\n\n"); (sensor s : sensors) { boolean regsuccess = sensormanager.registerlistener(this, sensormanager.getdefaultsensor(s.gettype()), sensormanager.sensor_delay_normal); tvavailablesensors.append(s.getname() + " (" + s.gettype() + ") " + regsuccess + "\n"); if (regsuccess) sensormanager.unregisterlistener(this, sensormanager.getdefaultsensor(s.gettype())); } }
but receive status few sensors: accelerometer, ambient light, gyroscope, magnetic field, orientation, rotation vector, linear acceleration , gravity. (and didn't receive status step detector\counter, significant motion, etc.)
someone knows how can verify sensor supported on device , no?
edit:
to clear: know device not support sensors want receive list available sensors , status 1 support , no.
for example, have nexus 10, should receive list this:
accelerometer true
ambient ligh true
...
step counter false
significant motion false
i think such api not available, need check each of sensor type in code:
private sensormanager msensormanager; ... msensormanager = (sensormanager) getsystemservice(context.sensor_service); if (msensormanager.getdefaultsensor(sensor.type_magnetic_field) != null){ // success! there's magnetometer. } else { // failure! no magnetometer. }
and documentation quotes these type of sensors:
type_ambient_temperature type_game_rotation_vector type_geomagnetic_rotation_vector type_gravity type_gyroscope type_gyroscope_uncalibrated type_light type_linear_acceleration type_magnetic_field type_magnetic_field_uncalibrated type_orientation type_pressure type_proximity type_relative_humidity type_rotation_vector type_significant_motion type_step_counter type_step_detector type_temperature
Comments
Post a Comment