Android Question Trying to trigger Sensor_Changed for getting Phonesensor 19

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 Pedometer 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 Label3 As Label
    Private Label2 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
        Pedometer.Initialize(19)
    End If
End Sub

Sub Activity_Resume
    If Pedometer.StartListening ("19") = False Then
        Label1.Text = "Pedometer not supported!"
    End If

End Sub

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


Sub Pedometer_SensorChanged (Values() As Float)
    If Sender = 19 Then
        Label1.Text = NumberFormat((0), 0, 3)
        Else
            Label1.Text = "Somethings wrong"
    End If
End Sub

Is what I'm trying to do. Trying to get the steps taken from this sensor but it somehow doesn't trigger or i'm miscalling the sensor somewhere...
 

DonManfred

Expert
Licensed User
Longtime User
Sub Activity_Resume
If Pedometer.StartListening ("19") = False Then
Label1.Text = "Pedometer not supported!"
End If

End Sub
19 is the "EventName"?

Try to put "Pedometer" here
 
Upvote 0

Servaas

Member
Licensed User
I did and it now gives me a zero on the label. No matter how much I walk it :) I also did this;

B4X:
If Sender = Pedometer Then
        Label1.Text = NumberFormat((0), 0, 3)
        Else
            Label1.Text = "Somethings wrong"
    End If

I realise I may be in a little over my head, but I have a really cool idea in mind and I really need steps taken. So you are helping me a great deal!
 
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 Pedometer 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 Label3 As Label
    Private Label2 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
        Pedometer.Initialize(19)
    End If
   
End Sub

Sub Activity_Resume
    If Pedometer.StartListening ("Pedometer") = False Then
        Label1.Text = "Pedometer not supported!"
    End If
End Sub

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


Sub Pedometer_SensorChanged (Values() As Float)
    If Sender = Pedometer Then
        Label1.Text = NumberFormat((0), 0, 3)
    Else
            Label1.Text = "Somethings wrong"
    End If
End Sub

This is what I have now. Except the Label1 text is not updating past 0.
 
Upvote 0

Servaas

Member
Licensed User
Looks correct. Use Log to understand what is happening.

Add Log(Values(0)) to Pedometer_SensorChanged. Is it raised?

The log is actually giving me values of the Sensor.

B4X:
Log (Values(0))
    If Sender = Pedometer Then
        Label1.Text = NumberFormat(Values(0), 0 , 3)
    Else
            Label1.Text = "Somethings wrong"
    End If

Adding Values was the trick. It wouldn't fire for me before that. Thanks a lot Erel and DonManfred!
 
Upvote 0
Top