在Android设备查看传感器列表 [英] View Sensor list on android device

查看:195
本文介绍了在Android设备查看传感器列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新的Andr​​oid开发,我想创建一个显示传感器我的Andr​​oid设备上的列表中的应用程序。

我试图找到这一点,但没有成功。

您能帮帮我。

下面是解决如何做到这一点:

  ///////////////列表传感器//////////////////// //////////
listeCapteurs =(ListView控件)findViewById(R.id.ListView01);

的SensorManager的SensorManager =
(的SensorManager)getSystemService(Context.SENSOR_SERVICE);
名单<传感器> listSensor =
sensorManager.getSensorList(Sensor.TYPE_ALL);

名单<字符串> listSensorType =新的ArrayList<字符串>();

的for(int i = 0; I< listSensor.size();我++)
{
listSensorType.add(listSensor.get(listSensor.size() -  1-i)的.getName());
}
 

解决方案

试试这个code:

 的SensorManager经理=(的SensorManager)getSystemService(SENSOR_SERVICE);
    名单<传感器>传感器= mgr.getSensorList(Sensor.TYPE_ALL);
    对于(传感器传感器:传感器){
        Log.d(传感器,+ sensor.getName());
    }
 

我的输出是:

  10-28 21:34:03.224:D /传感器(27760):BMA150 3轴加速度计
10-28 21:34:03.224:D /传感器(27760):AK8973 3轴磁场传感器
10-28 21:34:03.224:D /传感器(27760):AK8973方向传感器
10-28 21:34:03.224:D /传感器(27760):CM3602接近传感器
10-28 21:34:03.224:D /传感器(27760):CM3602光传感器
10-28 21:34:03.224:D /传感器(27760):重力感应
10-28 21:34:03.224:D /传感器(27760):线性加速度传感器
10-28 21:34:03.224:D /传感器(27760):旋转矢量传感器
 

I am a new to Android development and I would like to create an application which shows the list of sensors on my Android device.

I tried to find this but without the success.

Can you please help me.

Here is the solution how to do this:

///////////////  List of Sensors  //////////////////////////////
listeCapteurs = (ListView) findViewById(R.id.ListView01);

SensorManager sensorManager=
(SensorManager)getSystemService(Context.SENSOR_SERVICE);
List<Sensor> listSensor=
sensorManager.getSensorList(Sensor.TYPE_ALL);

List<String> listSensorType = new ArrayList<String>();

for(int i=0; i<listSensor.size(); i++)
{
listSensorType.add(listSensor.get(listSensor.size()-1-i).getName());
}

解决方案

Try this code:

    SensorManager mgr = (SensorManager) getSystemService(SENSOR_SERVICE);
    List<Sensor> sensors = mgr.getSensorList(Sensor.TYPE_ALL);
    for (Sensor sensor : sensors) {
        Log.d("Sensors", "" + sensor.getName());
    }

my output is:

10-28 21:34:03.224: D/Sensors(27760): BMA150 3-axis Accelerometer
10-28 21:34:03.224: D/Sensors(27760): AK8973 3-axis Magnetic field sensor
10-28 21:34:03.224: D/Sensors(27760): AK8973 Orientation sensor
10-28 21:34:03.224: D/Sensors(27760): CM3602 Proximity sensor
10-28 21:34:03.224: D/Sensors(27760): CM3602 Light sensor
10-28 21:34:03.224: D/Sensors(27760): Gravity Sensor
10-28 21:34:03.224: D/Sensors(27760): Linear Acceleration Sensor
10-28 21:34:03.224: D/Sensors(27760): Rotation Vector Sensor

这篇关于在Android设备查看传感器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆