在第二代智能手机问世之后,安卓手机中的传感器就变得越来越多了。
这次笔记就认识一下安卓内置传感器的种类吧。
如果想要获取安卓手机中所有的内置传感器的名字:
import android.hardware.Sensor; import android.hardware.SensorManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import java.util.List; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); for(Sensor sensor: sensors){ System.out.println(sensor.getName()); } } }
运行结果:
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: LIS3DH
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: AK8963
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Orientation
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: BMP180
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: ISL29028
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: ISL29028
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: L3GD20
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: BMP180
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Gravity
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Linear Acceleration
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: AMD
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: RMD
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: VMD
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Rotation Vector
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Rotation Vector Sensor
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Gravity Sensor
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Linear Acceleration Sensor
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Orientation Sensor
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: Corrected Gyroscope Sensor
07-14 23:58:48.148 11693-11693/bhu.com.myapplication I/System.out: BMP180
我用的测试机是小米2s,上面的运行结果打印出了小米2s内置的所有传感器。