leidiqiu 发表于 2013-1-15 02:27:58

Android 开发 — 显示手机传感器

Android 开发包标准有8个传感器:
 

[*]Sensor.TYPE_ACCELEROMETER

[*]加速度计 (X, Y, Z) m/s2

[*]Sensor.TYPE_GYROSCOPE

[*]陀螺仪 (X, Y, Z) degrees

[*]Sensor.TYPE_LIGHT

[*]光照 (single) lux

[*]Sensor.TYPE_MAGNETIC_FIELD

[*]磁力计 (X, Y, Z) microteslas

[*]Sensor.TYPE_ORIENTATION

[*]方位传感器 (X, Y, Z) degrees

[*]Sensor.TYPE_PRESSURE

[*]压力传感器 (single) kilopascals 测量加在手机设备上的压力

[*]Sensor.TYPE_PROXIMITY

[*]距离传感器 (single) meters 典型应用为接听电话时,根据光照,声音估计距离

[*]Sensor.TYPE_TEMPERATURE

[*]温度传感器 (single) degrees Celsius 电池温度,或是具体传感器温度,看具体实现

手机型号不同,硬件实现有所区别。
 
读取传感器代码如下:
package com.ldq.sensor;import java.util.List;import android.app.Activity;import android.hardware.Sensor;import android.hardware.SensorManager;import android.os.Bundle;import android.widget.LinearLayout;import android.widget.TextView;public class ExSensor extends Activity {private LinearLayout layout;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);layout = (LinearLayout) findViewById(R.id.LinearLayout01);SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);List<Sensor> list = sm.getSensorList(Sensor.TYPE_ALL);TextView text = new TextView(this);text.setText("传感器数量:" + list.size());layout.addView(text);TextView[] name = new TextView;for (int i = 0; i < list.size(); i++) {name = new TextView(this);name.setText((i + 1) + " : " + list.get(i).getName());layout.addView(name);}}} 
页: [1]
查看完整版本: Android 开发 — 显示手机传感器