Notes wk10 sensor & lbs

Most Android-powered devices have built-in sensors that measure motion, orientation and various environmental conditions. We can access sensors available on the device and acquire raw sensor data by using the Android sensor framework. There are software-based and hardware-based sensors.

The sensor framework is part of the android.hardware package and includes below classes and interfaces:
SensorManager
Sensor
SensorEvent
SensorEventListener

Attn: make sure to DISABLE sensors we don’t need, especially when our activity is paused.

–register under onResume();
–unRegister under onPause();

  @Override
    protected void onResume() {
        super.onResume();
        mSensorManager.registerListener(this,mSensor,SensorManager.SENSOR_DELAY_UI);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mSensorManager.unregisterListener(this);
    }

References:
Sensor overview:
http://developer.android.com/guide/topics/sensors/sensors_overview.html

發佈了38 篇原創文章 · 獲贊 9 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章