写入血压数据
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您的应用可以通过写入 com.google.blood_pressure
来记录血压数据
数据类型。在此数据类型中,每个数据点代表一个瞬时
血压读数。数据点包含收缩压和
舒张压、读取期间的身体位置以及身体的位置
进行测量的位置
systolic
和 diastolic
字段为必填字段,其他所有字段均为选填字段。
systolic
(较大数字)和 diastolic
(较小数字)的压力为
以毫米汞柱为单位。
- 如果已指定,正文位置必须具有以下值之一:
<ph type="x-smartling-placeholder">
</ph>
1
- 站立
2
- 坐下
3
- 躺着
4
- 半卧
如果已指定,测量位置必须具有以下值之一:
1
- 左手腕
2
- 右手腕
3
- 左上臂
4
- 右上臂
Android
如需写入血压数据点,请创建一个新的 DataSource
共 TYPE_BLOOD_PRESSURE
个,
如以下示例中所示。
val bloodPressureSource = DataSource.Builder()
.setDataType(TYPE_BLOOD_PRESSURE)
// ...
.build()
val bloodPressure = DataPoint.builder(bloodPressureSource)
.setTimestamp(timestamp, TimeUnit.MILLISECONDS)
.setField(FIELD_BLOOD_PRESSURE_SYSTOLIC, 120.0f)
.setField(FIELD_BLOOD_PRESSURE_DIASTOLIC, 80.0f)
.setField(FIELD_BODY_POSITION, BODY_POSITION_SITTING)
.setField(
FIELD_BLOOD_PRESSURE_MEASUREMENT_LOCATION,
BLOOD_PRESSURE_MEASUREMENT_LOCATION_LEFT_UPPER_ARM)
.build()
REST
创建数据源
要写入血压数据点,请创建新的数据源
HTTP 方法
POST
Request URL
https://www.googleapis.com/fitness/v1/users/me/dataSources
请求正文
{
"dataStreamName": "BloodPressure",
"type": "raw",
"application": {
"detailsUrl": "http://example.com",
"name": "My Example App",
"version": "1"
},
"dataType": {
"name": "com.google.blood_pressure"
}
}
答案
如果数据源已成功创建,您会收到 200 OK
HTTP
响应状态代码。响应正文包含
数据源,包括 datasource.dataStreamId
属性。使用此 ID
用作 dataSourceId
以添加数据。
添加血压数据
通过创建 com.google.blood_pressure
类型的数据点来添加数据。
HTTP 方法
PATCH
Request URL
https://www.googleapis.com/fitness/v1/users/me/dataSources/datasource.dataStreamId/datasets/1574159699023000000-1574159699023000000
请求正文
为清楚起见,下面显示的 JSON 正文带有注释,以便显示
运行状况字段常量的使用。
{
"dataSourceId": "datasource.dataStreamId",
"maxEndTimeNs": 1574159699023000000,
"minStartTimeNs": 1574159699023000000,
"point": [
{
"dataTypeName": "com.google.blood_pressure",
"endTimeNanos": 1574159699023000000,
"startTimeNanos": 1574159699023000000,
"value": [
{
"fpVal": 120.0 // systolic
},
{
"fpVal": 80.0 // diastolic
},
{
"intVal": 2 // Body position enum value for sitting
},
{
"intVal": 3 // Location enum value for left upper arm
}
]
}
]
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eGoogle Fit allows recording blood pressure data using the \u003ccode\u003ecom.google.blood_pressure\u003c/code\u003e data type, including systolic and diastolic values, body position, and measurement location.\u003c/p\u003e\n"],["\u003cp\u003eRequired fields for blood pressure data are \u003ccode\u003esystolic\u003c/code\u003e and \u003ccode\u003ediastolic\u003c/code\u003e pressure, measured in mmHg.\u003c/p\u003e\n"],["\u003cp\u003eBody position and measurement location can optionally be specified using predefined enum values.\u003c/p\u003e\n"],["\u003cp\u003eYou can write blood pressure data points on Android using the Google Fit API and on the REST API by creating a data source and adding data points.\u003c/p\u003e\n"]]],[],null,["# Write Blood Pressure Data\n\n| **Note:** Because health data is potentially sensitive, Google Fit [restricts read / write access to health data types](/fit/datatypes/restricted).\n\nYour app can record blood pressure data by writing to the `com.google.blood_pressure`\ndata type. In this data type, each data point represents a single instantaneous\nblood pressure reading. The data point contains fields for the systolic and\ndiastolic pressure, body position during the reading, and location on the body\nwhere the measurement was performed.\n\n- The `systolic` and `diastolic` fields are required, all others are optional.\n- Pressures for `systolic` (upper number) and `diastolic` (lower number) are measured in mmHg.\n- If specified, body position must have one of the following values:\n - `1` - standing up\n - `2` - sitting down\n - `3` - lying down\n - `4` - semi-reclined\n- If specified, measurement location must have one of the following values:\n\n - `1` - left wrist\n - `2` - right wrist\n - `3` - left upper arm\n - `4` - right upper arm\n\n### Android\n\nTo write a blood pressure data point, create a new [`DataSource`](/android/reference/com/google/android/gms/fitness/data/DataSource)\nof [`TYPE_BLOOD_PRESSURE`](/android/reference/com/google/android/gms/fitness/data/HealthDataTypes#TYPE_BLOOD_PRESSURE),\nas shown in the following example. \n\n val bloodPressureSource = DataSource.Builder()\n .setDataType(TYPE_BLOOD_PRESSURE)\n // ...\n .build()\n\n val bloodPressure = DataPoint.builder(bloodPressureSource)\n .setTimestamp(timestamp, TimeUnit.MILLISECONDS)\n .setField(FIELD_BLOOD_PRESSURE_SYSTOLIC, 120.0f)\n .setField(FIELD_BLOOD_PRESSURE_DIASTOLIC, 80.0f)\n .setField(FIELD_BODY_POSITION, BODY_POSITION_SITTING)\n .setField(\n FIELD_BLOOD_PRESSURE_MEASUREMENT_LOCATION,\n BLOOD_PRESSURE_MEASUREMENT_LOCATION_LEFT_UPPER_ARM)\n .build()\n\n### REST\n\nCreate a data source\n--------------------\n\nTo write a blood pressure data point, create a new data data source\n\n**HTTP method** \n\n POST\n\n**Request URL** \n\n```html\nhttps://www.googleapis.com/fitness/v1/users/me/dataSources\n```\n\n**Request body** \n\n {\n \"dataStreamName\": \"BloodPressure\",\n \"type\": \"raw\",\n \"application\": {\n \"detailsUrl\": \"http://example.com\",\n \"name\": \"My Example App\",\n \"version\": \"1\"\n },\n \"dataType\": {\n \"name\": \"com.google.blood_pressure\"\n }\n }\n\n**Response**\n\nIf your data source was created successfully, you'll get a [`200 OK`](https://httpstatuses.com/200) HTTP\nresponse status code. The response body contains a JSON representation of\nthe data source, including a `datasource.dataStreamId` property. Use this ID\nas the `dataSourceId` to add data.\n\nAdd blood pressure data\n-----------------------\n\nAdd data by creating a data point of type `com.google.blood_pressure`.\n\n**HTTP method** \n\n PATCH\n\n**Request URL** \n\n```html\nhttps://www.googleapis.com/fitness/v1/users/me/dataSources/datasource.dataStreamId/datasets/1574159699023000000-1574159699023000000\n```\n\n**Request body**\n\nFor clarity the JSON body shown below is annotated with comments, to show\nthe use of health field constants. \n\n {\n \"dataSourceId\": \"datasource.dataStreamId\",\n \"maxEndTimeNs\": 1574159699023000000,\n \"minStartTimeNs\": 1574159699023000000,\n \"point\": [\n {\n \"dataTypeName\": \"com.google.blood_pressure\",\n \"endTimeNanos\": 1574159699023000000,\n \"startTimeNanos\": 1574159699023000000,\n \"value\": [\n {\n \"fpVal\": 120.0 // systolic\n },\n {\n \"fpVal\": 80.0 // diastolic\n },\n {\n \"intVal\": 2 // Body position enum value for sitting\n },\n {\n \"intVal\": 3 // Location enum value for left upper arm\n }\n ]\n }\n ]\n }"]]