Android Question Request for providing an example of how to access/program Android Fitness Watch reg.

beelze69

Active Member
Licensed User
Longtime User
Hi,

I require information on how to access/program Android Fitness watches using B4A Application.

Ps. help me.

Thanks
 
Last edited:

beelze69

Active Member
Licensed User
Longtime User
Hi,

I require information on how to access/program Android Fitness watches using B4A Application.

Ps. help me.

Thanks
Hi Erel,

Addressing this post specifically to you since the above 'general post' sent yesterday did not elicit any response so far.

Ps. help Thanks...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
GoogleFitnessApiClient

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim fc As FitnessClient
    Private btnLogin As Button
    Dim req As DataReadRequestBuilder
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("Layout1")
    'Log(DateTime.DeviceDefaultDateFormat)
    'DateTime.DateFormat ="dd.MM.yyyy"
End Sub
Sub Activity_Resume
    Dim si As Intent = Activity.GetStartingIntent
    If si <> Null Then
        Log(si.ExtrasToString)
    End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub btnLogin_Click
    fc.Initialize("Fitness")
End Sub
Sub Fitness_onAccount(successful As Boolean)
    Log($"Fitness_onAccount(${successful})"$)
    Dim oldformat As String = DateTime.DeviceDefaultDateFormat
    DateTime.DateFormat = "dd.MM.YYYY"
    Dim begintime As Long = DateTime.DateTimeParse("01.01.2018","00:00:00")
    Dim endtime As Long = DateTime.Now
    Log("BeginTime = "&begintime)
    Log("  EndTime = "&endtime)
    req.Initialize("Fitness").bucketByTime(1,req.tuDAYS).aggregate(req.dtAGGREGATE_STEP_COUNT_DELTA,req.dtAGGREGATE_STEP_COUNT_DELTA).setTimeRange(begintime,endtime,req.tuMILLISECONDS)
    fc.readData(req.build)
    
    DateTime.DateFormat = oldformat
    
    'fc.Subscribe(req.dtTYPE_STEP_COUNT_DELTA) ' One need to register for step cound
    'fc.listSubscriptions(req.dtTYPE_STEP_COUNT_DELTA) ' see list on data suibscribed
    
    
End Sub
Sub Fitness_DataRead(successful As Boolean, response As DataReadResponse)
    Log($"Fitness_DataRead(${successful},${response})"$)
    'Log(response.DataType)
    If response.DataPoints <> Null Then
        Log(response.DataPoints.Size)
        If response.DataPoints.Size > 0 Then
            Dim l As List = response.DataPoints
            For i = 0 To l.Size-1
                Dim bucket As Bucket = l.Get(i)
                Log(bucket)
                Log($"$date{bucket.getStartTime(req.tuMILLISECONDS)} $time{bucket.getStartTime(req.tuMILLISECONDS)} - $time{bucket.getEndTime(req.tuMILLISECONDS)}  }"$)
                Dim datalist As List = bucket.DataSets
                If datalist <> Null And datalist.Size > 0 Then
                    For u = 0 To datalist.Size-1
                        Log(datalist.Get(u))
                        Dim ds As DataSet = datalist.Get(u)
                        Dim datapoints As List = ds.DataPoints
                        If datapoints <> Null And datapoints.Size> 0 Then
                            For t=0 To datapoints.Size-1
                                Dim dp As DataPoint = datapoints.Get(t)
                                Log($"Value = ${dp.getValue(req.dfFIELD_STEPS)}"$)
                            Next
                        End If
                    Next
                End If
            Next
        End If
    End If
    
End Sub
 
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
GoogleFitnessApiClient

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim fc As FitnessClient
    Private btnLogin As Button
    Dim req As DataReadRequestBuilder
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("Layout1")
    'Log(DateTime.DeviceDefaultDateFormat)
    'DateTime.DateFormat ="dd.MM.yyyy"
End Sub
Sub Activity_Resume
    Dim si As Intent = Activity.GetStartingIntent
    If si <> Null Then
        Log(si.ExtrasToString)
    End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub btnLogin_Click
    fc.Initialize("Fitness")
End Sub
Sub Fitness_onAccount(successful As Boolean)
    Log($"Fitness_onAccount(${successful})"$)
    Dim oldformat As String = DateTime.DeviceDefaultDateFormat
    DateTime.DateFormat = "dd.MM.YYYY"
    Dim begintime As Long = DateTime.DateTimeParse("01.01.2018","00:00:00")
    Dim endtime As Long = DateTime.Now
    Log("BeginTime = "&begintime)
    Log("  EndTime = "&endtime)
    req.Initialize("Fitness").bucketByTime(1,req.tuDAYS).aggregate(req.dtAGGREGATE_STEP_COUNT_DELTA,req.dtAGGREGATE_STEP_COUNT_DELTA).setTimeRange(begintime,endtime,req.tuMILLISECONDS)
    fc.readData(req.build)
   
    DateTime.DateFormat = oldformat
   
    'fc.Subscribe(req.dtTYPE_STEP_COUNT_DELTA) ' One need to register for step cound
    'fc.listSubscriptions(req.dtTYPE_STEP_COUNT_DELTA) ' see list on data suibscribed
   
   
End Sub
Sub Fitness_DataRead(successful As Boolean, response As DataReadResponse)
    Log($"Fitness_DataRead(${successful},${response})"$)
    'Log(response.DataType)
    If response.DataPoints <> Null Then
        Log(response.DataPoints.Size)
        If response.DataPoints.Size > 0 Then
            Dim l As List = response.DataPoints
            For i = 0 To l.Size-1
                Dim bucket As Bucket = l.Get(i)
                Log(bucket)
                Log($"$date{bucket.getStartTime(req.tuMILLISECONDS)} $time{bucket.getStartTime(req.tuMILLISECONDS)} - $time{bucket.getEndTime(req.tuMILLISECONDS)}  }"$)
                Dim datalist As List = bucket.DataSets
                If datalist <> Null And datalist.Size > 0 Then
                    For u = 0 To datalist.Size-1
                        Log(datalist.Get(u))
                        Dim ds As DataSet = datalist.Get(u)
                        Dim datapoints As List = ds.DataPoints
                        If datapoints <> Null And datapoints.Size> 0 Then
                            For t=0 To datapoints.Size-1
                                Dim dp As DataPoint = datapoints.Get(t)
                                Log($"Value = ${dp.getValue(req.dfFIELD_STEPS)}"$)
                            Next
                        End If
                    Next
                End If
            Next
        End If
    End If
   
End Sub
Hi Don !

Thanks a lot.. I will get back to you more when I try this out...
 
Upvote 0
Top