Android Question A simple pedometer label...

Servaas

Member
Licensed User
Hello, I have looked through the various examples I could find beeing these:
https://www.b4x.com/android/forum/threads/orientation-and-accelerometer.6647/#content

The original thread if you will, and for a bit it seemed like this would provide all the sensory goodies. But ill be honest with you, for someone new, its a bit daunting. I'm unsure what int or strings I need to call to get them into my own variables.

https://www.b4x.com/android/forum/threads/phonesensorsextra-library.43175/#content
Is way too advanced i'm not even sure where to put them nvm using them with out an example.

https://www.b4x.com/android/forum/threads/android-shake-event-with-phonesensors.9857/#content
Also did not really help me...

https://www.b4x.com/android/forum/threads/kitkat-step-detector.40563/#content

Okay so I do that... but still no clue where to get the step taken or steps taken from? I'm probably too dumb but the code seems way more advanced...

B4X:
Sub Process_Globals
    Dim ps As PhoneSensors
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        ps.Initialize(ps.TYPE_ACCELEROMETER)
    End If
End Sub

Sub Activity_Resume
    If ps.StartListening("Sensor") = False Then
        Log("Sensor is not supported.")
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    ps.StopListening
End Sub

Sub Sensor_SensorChanged (Values() As Float)
    Values(2) < -8 Then 'Check Z value
        Log("Device face down")
    Else
        Log("Device face up")
    End If
End Sub

This is very helpful! This is clear and easy on the eyes. But I still struggle how to get the steps taken and step taken events.

I'm sure the example from Erel is great but i'm having trouble getting data out of it. And i'm sure its me but if someone could explain this to me id be very grateful.
 

An Schi

Well-Known Member
Licensed User
Hhmm, i think you want to take too much steps at once :rolleyes:
My suggestion is to split your pedometer in smaller parts and when you achieved all the smaller steps you can combine them to your project.
Suggested worklow:
1)
Make an app that knows if your phone is facing up or down.
When done add a function that counts how often you flipped your phone
2)
Make an app that reacts if you shake your phone
When done you can add a measurement of the shaking
3)
Think about how your phone is shaked while beeing in your pocket while walking.
Try to translate that thoughts to to conditions for your measurement app
 
Upvote 0

Servaas

Member
Licensed User
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Phone, PhoneStepsTaken As PhoneSensors
   
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")
    If FirstTime Then
        PhoneStepsTaken.Initialize(19)
    ''Phone.Initialize(Phone.TYPE_ACCELEROMETER)
   
        End If
       
        ''Phonesteptaken(18, "TYPE_STEP_DETECTOR", False)
        ''Phoneupordown(19, "TYPE_STEP_COUNTER", False)
End Sub

Sub Activity_Resume
    If Phone.StartListening("Sensor") = False Then
        Log("Sensor is not supported.")
    End If
    If PhoneStepsTaken.StartListening("Sensor") = False Then
        Log("Sensor is not supported.")
    End If
    End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Phone.StopListening
    PhoneStepsTaken.StopListening
   
End Sub

Sub Sensor_SensorChanged (Values() As Float)
    If Values(2) < -8 Then 'Check Z value
        Label1.Text = "Device face down"
    Else
        Log(1)
        Label1.Text = "Device face up"
    End If
End Sub

This is as bare as I could make it. Now where my problems is at the Sub Sensor_SensorChanged.
How do I get int, strings etc out of PhoneStepsTaken? The example from which I have taken this code works, I get a report when device is facing up or down. But i'm unsure how to parse the data out of PhoneStepsTaken...
 
Upvote 0
Top