android sensor 之手掌接近或远离

实现接口  SensorEventListener

实例化:

private SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);

private Sensor sensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    
 sm.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);

@Override
  public void onAccuracyChanged(Sensor arg0, int arg1) {
    Log.debug(TAG, "onAccuracyChanged:" + arg1);
  }

@Override

  public void onSensorChanged(SensorEvent event) {
    float[] types = event.values;
    if (types[0] == 0.0) {
      Log.debug(TAG, "onSensorChanged: hand in");

    } else {

       Log.debug(TAG, "onSensorChanged: hand out");

    }    

  }

你可能感兴趣的:(android sensor 之手掌接近或远离)