Sensors -- Android Step_Counter ?
I have a Delphi Berlin Android application that needs to access the Android Step_Counter. I have researched for a few days and find no Delphi related references or examples for the Android step sensors referenced below.
I could really use some help at this point. Is there any way to access/add support for the step_counter in Delphi ?
A constant describing a step counter sensor.
A sensor of this type returns the number of steps taken by the user since the last reboot while activated. The value is returned as a float (with the fractional part set to zero) and is reset to zero only on a system reboot. The timestamp of the event is set to the time when the last step for that event was taken. This sensor is implemented in hardware and is expected to be low power. If you want to continuously track the number of steps over a long period of time, do NOT unregister for this sensor, so that it keeps counting steps in the background even when the AP is in suspend mode and report the aggregate count when the AP is awake. Application needs to stay registered for this sensor because step counter does not count steps if it is not activated. This sensor is ideal for fitness tracking applications. It is defined as an
SensorEvent.values for more details.
Constant Value: 19 (0x00000013)TYPE_STEP_DETECTOR
A constant describing a step detector sensor.
A sensor of this type triggers an event each time a step is taken by the user. The only allowed value to return is 1.0 and an event is generated for each step. Like with any other event, the timestamp indicates when the event (here the step) occurred, this corresponds to when the foot hit the ground, generating a high variation in acceleration. This sensor is only for detecting every individual step as soon as it is taken, for example to perform dead reckoning. If you only need aggregate number of steps taken over a period of time, register for
TYPE_STEP_COUNTER instead. It is defined as a
SensorEvent.values for more details.
Constant Value: 18 (0x00000012)
I have been able to access the Android Sensor Manager and have it provide the Step_Counter sensor type.
I don't see how to then register the SensorEventListener within my form.
The location sensor examples use a .Create but that is not available with the SensorEventListener.
I know it is likely something very simple but I have been staring at the code too long to see it now.
Here is where I am stuck :
bListen := FSensorManager.registerlistener(SensorEventListener,FSensor,5000);
The SensorEventListener is nil and I don't see how to create the SensorEventListener in the form.
BTW -- the error message and Monitor messages are in the attached files.
So as part of the AndroidAPI JNI education I went through the excellent information from Brian Long.
While things make more sense now, I tried to replicate a simple demo using the Vibrate example.
I tried it on Android platforms from 22-25 with the appropriate Android devices running 5.1.1. to 7.1.2.
Using Brian's example code, the app always crashes at the SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_SERVICE).
I also tried to use the AndroidHelper getSystemService with the same fail.
So if the simple Vibrate example does not work, I don't feel very confident about forging ahead with the actual challenge of using the step_counter. Is anyone having similair results with the Vibrate example ?
I am using Delphi Berlin 10.1, 10.2.
I started putting together all the units needed for this using the GH Android-23 units Eli kindly provided.
I also tried to wrap my head around how this might work compared to the location services.
I was able to make the location work and then tried to apply a similar approach for the Motion Step_COUNTER.
I am still looking for the Android-23 Android.Hardware.Sensors.EventListener and will try again later tonight.
I was struggling on how to use the SensorManager to get the default motion sensor (TYPE_STEP_COUNTER).
If anyone has any examples, they would be much appreciated.
Thanks for the suggestion. I have not worked with Androidapi.JNI yet but it looks like I might have to invest in that education. Any examples in the sensor area would be much appreciated. I will get started on digesting how to use the JNI etc.