Android Question Interested in a wrap for Google Fitness/Fitbit

DonManfred

Expert
Licensed User
Longtime User
Today i get a delivery of my new Fitbit 2 Charge device.

I already started a wrap to use the Data i can get from Google Fitness.

B4X:
#AdditionalJar: com.google.android.gms:play-services-fitness
#AdditionalJar: com.google.android.gms:play-services-auth

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

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.
    Dim fc As FitnessClient
    Private btnLogin As Button
    Dim heutestart, heuteende As Long
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")
  
    heutestart = DateTime.DateTimeParse(DateTime.Date(DateTime.Now),"00:00:00")
    heuteende = DateTime.Now
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"
    Log(DateTime.Date(DateTime.Now))
    Dim begin As Long = DateTime.DateTimeParse(DateTime.Date(DateTime.Now),"00:00:00")
    Dim req As DataReadRequestBuilder
    req.Initialize("Fitness").bucketByTime(1,req.tuHOURS).aggregate(req.dtTYPE_STEP_COUNT_DELTA,req.dtAGGREGATE_STEP_COUNT_DELTA).setTimeRange(begin,DateTime.Now,req.tuMICROSECONDS)
    DateTime.DateFormat = oldformat
    fc.readData(req.build)
End Sub
Sub Fitness_DataRead(successful As Boolean, response As DataReadResponse)
    Log($"Fitness_DataRead(${successful},${response})"$)
    Log(response.DataType)
    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)
        Next
    End If
  
End Sub

Make sure to check the Manifestentries needed.

Mandatory:
B4X:
'************ Google Play Services Base ************
AddApplicationText(
   <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"/>
    <meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************
'************ Firebase Auth ************
AddApplicationText(
  <activity android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:excludeFromRecents="true"
  android:exported="false" />

  <service
  android:name="com.google.android.gms.auth.api.signin.RevocationBoundService"
  android:exported="true"
  android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />
)


Probably only needed when we later want to fetch new Data automatically. Don´t know exactly... At this time i am coding blind as i do not have a Fitbit device which does provide Data :D

B4X:
AddManifestText(
<intent-filter>
    <action android:name="vnd.google.fitness.VIEW" />
    <data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.cumulative" />
    <data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.delta" />
</intent-filter>

)

If YOU have a Fitbit-Device: Would you mind to check if you get correct Data? Please post your results here in the Thread.
 

Attachments

  • GooglefitnessEx1.zip
    8.8 KB · Views: 193
  • GoogleFitnessV0.05.zip
    21.7 KB · Views: 179
Last edited:

BillMeyer

Well-Known Member
Licensed User
Longtime User
The master strikes again !!
 
Upvote 0
Top