我对如何使用测量有问题——MotionEvent 的 getPressure。我想测量用户触摸屏幕时施加在屏幕上的压力。任何人都可以给我一些样品左右。
还有一个问题:回归getPressure:1.0
是由最强的媒体或设备定义的。
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);// Get an instance of the sensor service, and use that to get an instance of a particular sensor.
public final void onSensorChanged(SensorEvent event) {
float millibars_of_pressure = event.values[0];//use the pressure value
}
public class MySensorActivity extends Activity implements SensorEventListener{
private SensorManager mSensorManager;
private Sensor mPressure;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
public void onSensorChanged(SensorEvent event) {
float millibars_of_pressure = event.values[0];
Log.e("sensorValues",String.valueOf(millibars_of_pressure));
}
@Override
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mPressure, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onPause() {
super.onPause();
mSensorManager.unregisterListener(this);
}
}