How to log data from Android Motion Sensors at a fixed rate

前端 未结 5 1892
说谎
说谎 2020-12-31 13:47

I\'m learning the Basics of Android programming.

I have a simple android test application in which i log the accelerometer,magnetometer and the orientation data to a

5条回答
  •  轮回少年
    2020-12-31 14:09

    I have been trying to figure out how can I have very long delays with sensors, and so far I have been successful. The documentation on the developer.android talks that the delay time can be specified in microseconds, below is a large number I tried:

    // Initialize in onCreate
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE)
    mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    
    // Register the listener, and play around with delay
    mSensorManager.registerListener(this, mLight, 200000000);
    

    However note the LogCat dump below - the onSensorChanged() - gets called as many as 4 times a second... I am trying to figure out getting larger delays with no success so far!!!

    01-14 06:58:07.088: D/IOE Sensors(20933): onSensorChanged called, the event is: android.hardware.SensorEvent@42849f70 01-14 06:58:07.268: D/IOE Sensors(20933): onSensorChanged called, the event is: android.hardware.SensorEvent@42849f70 01-14 06:58:07.448: D/IOE Sensors(20933): onSensorChanged called, the event is: android.hardware.SensorEvent@42849f70 01-14 06:58:07.628: D/IOE Sensors(20933): onSensorChanged called, the event is: android.hardware.SensorEvent@42849f70 01-14 06:58:07.808: D/IOE Sensors(20933): onSensorChanged called, the event is: android.hardware.SensorEvent@42849f70 01-14 06:58:07.989: D/IOE Sensors(20933): onSensorChanged called, the event is: android.hardware.SensorEvent@42849f70 01-14 06:58:08.169: D/IOE Sensors(20933): onSensorChanged called, the event is: android.hardware.SensorEvent@42849f70

提交回复
热议问题