I'm trying to get this to work as well. I followed the bananas earned example on this page:
https://developer.garmin.com/connect-iq/api-docs/Toybox/FitContributor.html
but no data is saved for my custom datafield after the activity (walk) is completed and saved. Is there something else that I need to do? Also I set the field ID to 0, but how do I know if this conflicts or not with an existing ID that may be being used , custom or native?
You need to createField(), and make sure you have the data you want for that field at all times using setData() (I do it in compute() on every call.)
You need to have the xml file that defines how that data will be displayed in Garmin Connect, and for that data to be displayed, the DF needs to be installed from the app store.
As far as the field ID, it's really not just a 0. It's a combo of that plus your app ID, so it's only got to be unique in your data field.
Thanks,
Can you explain this more ? ==>
>> You need to have the xml file that defines how that data will be displayed in Garmin Connect, and for that data to be displayed
Do I need to create an XML file or does the user do it somehow manually or automatically?
It's used when you compile to build the fit_contributions.jso which is included in the iq file for the store.
For example, in a DF initialize(), I have this:
field=createField("piTemp",0,FitContributor.DATA_TYPE_FLOAT, {:mesgType => FitContributor.MESG_TYPE_RECORD});
in compute, this:
field.setData(tempValue);
And the fitContrib.xml has this:
<resources> <strings> <string id="temp_label">Temp</string> <string id="temp_units">F</string> <string id="temp_title">piTemp</string> </strings> <fitContributions> <fitField id="0" displayInChart="true" chartTitle="@Strings.temp_title" fillColor="ff0000" sortOrder = "1" precision="2" displayInActivityLaps="false" dataLabel="@Strings.temp_label" unitLabel="@Strings.temp_units"/> </fitContributions> </resources>
The result is this graph: