Google Fit API的DataSet对象 [英] DataSet Object for the Google Fit API
问题描述
目前正在使用Google Fit API,并且在Sessions API方面遇到了一些麻烦.我正在尝试为我的应用程序的锻炼插入一个会话,但是文档有点混乱.
Working with the Google Fit API at the moment and having a bit of trouble with the Sessions API. I'm trying to insert a session for my app's workouts but the documentation is a bit confusing.
在此代码段中,是Google信息页中的示例.
In this code snippet is an example from Google's info page. Where exactly do you get DataSet objects from and/or how do you create them from existing data?
// Create a session with metadata about the activity.
Session session = new Session.Builder()
.setName(SAMPLE_SESSION_NAME)
.setDescription("Long run around Shoreline Park")
.setIdentifier("UniqueIdentifierHere")
.setActivity(FitnessActivities.RUNNING)
.setStartTime(startTime, TimeUnit.MILLISECONDS)
.setEndTime(endTime, TimeUnit.MILLISECONDS)
.build();
// Build a session insert request
SessionInsertRequest insertRequest = new SessionInsertRequest.Builder()
.setSession(session)
.addDataSet(runningDataSet) //where does this come from???
.build();
这是指向Google Sessions API页面的链接(这是我在此代码中使用的页面):
Here is a link to Google Sessions API page (which is what I'm using for this code):
推荐答案
DataSet
来自DataSource
,因此您必须首先创建一个DataSource,然后简单地创建DataSet.create(yourDataSource);
A DataSet
comes from a DataSource
, so you will have to create a DataSource first, then simply DataSet.create(yourDataSource);
例如:
DataSource dataSource = new DataSource.Builder()
.setType(DataSource.TYPE_RAW)
.setDataType(exerciseDataType)
.setName(exercise.name)
.setAppPackageName(this)
.build();
DataSet dataSet = DataSet.create(dataSource);
...
dataSet.createDataPoint()....insert values :-)
这篇关于Google Fit API的DataSet对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!