0
我目前正在嘗試做一個Android演示,以約50Hz的採樣率測試光照水平。不過,我只能得到onSensorChanged
回撥2-3次。我的手機是xiaomi mi5s(lineage os 14.1安裝),Android 7.1。Android光傳感器採樣頻率太低
public class MainActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mLight;
@Override
public final void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
}
@Override
public final void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do something here if sensor accuracy changes.
}
@Override
public final void onSensorChanged(SensorEvent event) {
// The light sensor returns a single value.
// Many sensors return 3 values, one for each axis.
float lux = event.values[0];
Log.i("zz", lux + "");
// Do something with this sensor value.
}
@Override
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onPause() {
super.onPause();
mSensorManager.unregisterListener(this);
}
}
感謝您的回覆。我已經嘗試了SENSOR_DELAY_FASTEST,但它仍然每秒2-3次... – iampkuhz
然後這就是你能夠從傳感器中獲得的最多。它並不是真正爲你的用例設計的 –