android sensor 之手掌接近或遠離

實現接口  SensorEventListenerjava

實例化:ide

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");

    }    

  }
相關文章
相關標籤/搜索