java传感器名称和供应商Android
是否可以仅显示来自此的sensor name
和vendor
public class SensorikTestActivity extends Activity {
private ListView listView;
private SensorManager mSensorManager;
private List<Sensor> deviceSensors = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = ((ListView) findViewById(R.id.listView1));
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
listView.setAdapter(new ArrayAdapter<Sensor>(this,
安卓.R.layout.simple_list_item_1, deviceSensors));
}
}
实际上它显示了传感器的所有信息,但我只需要一些信息。谢谢
# 1 楼答案
没有内置的方法。你需要做一些编码
创建像
SensorDetails
这样的自定义对象,只使用您想要的属性(名称、供应商等)而不是
List<Sensor> deviceSensors
创建List<YourCustomClass>
。使用Sensor
列表中的值填充自定义对象,并将其设置为Adapter