Sensor.TYPE_STEP_DETECTOR not found on android Lollipop

I am developing a pedometer android app and for that I used Sensor.TYPE_STEP_DETECTOR which is available from android KitKat. Everything worked fine on Nexus 5 and Samsung Alpha, but then I tested my app on Moto G (Lollipop) and Nexus 4 (Lollipop), both devices return null when I try to get a sensor of type Sensor.TYPE_STEP_DETECTOR.

Here is my code:

 private boolean checkSensorAvailability() {
    SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
    Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
    if(sensor==null){return false;}

    return true;
}

      

As far as I know, this sensor requires an Accelerometer on the device. What's available on both devices.

Please help me to solve this problem.

thank

+3


source to share


3 answers


Some devices have simply dropped this feature (full wakeup).

The problem is energy consumption. If the phone wakes up the app processor every time a step occurs, it will consume more power and may result in poor battery life. From your phone, the manufacturer has decided NOT to support a "wake up" version of the sensor, which would turn on the phone when a step is detected.

fooobar.com/questions/2235564 / ...



As a workaround, I recommend looking at https://github.com/j4velin/Pedometer/blob/master/src/main/java/de/j4velin/pedometer/SensorListener.java

public void onSensorChanged(final SensorEvent event) {
    steps = (int) event.values[0];
    // ...
}

      

+1


source


Android documentation ( https://developer.android.com/about/versions/android-4.4.html ) says:

Both stepper sensors are hardware dependent (the Nexus 5 is the first device to support them), so you must check for availability with hasSystemFeature () using the FEATURE_SENSOR_STEP_DETECTOR and FEATURE_SENSOR_STEP_COUNTER constants.



Hence, the Nexus 4 and Moto G2 will not support it. You should check other devices.

0


source


Not all devices will support step sensors:

From Docs:

Both stepper sensors are hardware dependent (Nexus 5 is the first device to support them), so you should check for hasSystemFeature () using FEATURE_SENSOR_STEP_DETECTOR and FEATURE_SENSOR_STEP_COUNTER constants.

Found here: https://developer.android.com/about/versions/android-4.4.html

0


source







All Articles