1.传感器的采样率 1 SENSOR_DELAY_NORMAL(200000微秒)
2 SENSOR_DELAY_UI(60000微秒)
3 SENSOR_DELAY_GAME(20000微秒)
4 SENSOR_DELAY_FASTEST(0)微秒
设置传感器的原则:
尽量使用比较低的传感器采样率,这样系统的负荷比较小,同时可以省电
2.传感器的属性
1)传感器的名称
2)传感器制造商
3)传感器gonglv
4)传感器的resulotion;
MainActivity: 1 package org.gaolei.sensor03;
2
3 import android.app.Activity;
4 import android.content.Context;
5 import android.hardware.Sensor;
6 import android.hardware.SensorEvent;
7 import android.hardware.SensorEventListener;
8 import android.hardware.SensorManager;
9 import android.os.Bundle;
10
11 public class MainActivity extends Activity {
12 private SensorManager sensorManager;
13
14 @Override
15 public void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.main);
18
19 sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
20 Sensor lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
21
22 sensorManager.registerListener(new SensorEventListener() {
23
24 @Override
25 public void onSensorChanged(SensorEvent event) {
26 String sensorName = event.sensor.getName();
27 String sensorVendor = event.sensor.getVendor();
28 float resolution = event.sensor.getResolution();
29 float power = event.sensor.getPower();
30 double timestamp = event.timestamp;
31
32 System.out.println("sensor name--->" + sensorName);
33 System.out.println("sensor vendor--->" + sensorVendor);
34 System.out.println("sensor resolution--->" + resolution);
35 System.out.println("sensor power--->" + power);
36 System.out.println("sensor timestamp--->" + timestamp);
37
38 }
39
40 @Override
41 public void onAccuracyChanged(Sensor sensor, int accuracy) {
42 }
43 }, lightSensor, SensorManager.SENSOR_DELAY_GAME);
44 }
45 }