Ghi dữ liệu huyết áp
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Ứng dụng của bạn có thể ghi dữ liệu huyết áp bằng cách ghi vào com.google.blood_pressure
loại dữ liệu. Trong loại dữ liệu này, mỗi điểm dữ liệu biểu thị một
chỉ số huyết áp. Điểm dữ liệu này chứa các trường dành cho tâm thu và
áp suất tâm trương, vị trí cơ thể trong khi đo và vị trí trên cơ thể
nơi thực hiện phép đo.
Android
Để ghi một điểm dữ liệu huyết áp, hãy tạo một DataSource
mới
trong tổng số TYPE_BLOOD_PRESSURE
,
như trong ví dụ sau.
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()
Kiến trúc chuyển trạng thái đại diện (REST)
Tạo một nguồn dữ liệu
Để ghi một điểm dữ liệu huyết áp, hãy tạo một nguồn dữ liệu mới
Phương thức HTTP
POST
URL yêu cầu
https://www.googleapis.com/fitness/v1/users/me/dataSources
Nội dung yêu cầu
{
"dataStreamName": "BloodPressure",
"type": "raw",
"application": {
"detailsUrl": "http://example.com",
"name": "My Example App",
"version": "1"
},
"dataType": {
"name": "com.google.blood_pressure"
}
}
Đáp
Nếu tạo nguồn dữ liệu thành công, bạn sẽ nhận được một HTTP 200 OK
mã trạng thái phản hồi. Nội dung phản hồi chứa bản trình bày JSON của
nguồn dữ liệu, bao gồm cả tài sản datasource.dataStreamId
. Sử dụng mã này
dưới dạng dataSourceId
để thêm dữ liệu.
Thêm dữ liệu huyết áp
Thêm dữ liệu bằng cách tạo một điểm dữ liệu thuộc loại com.google.blood_pressure
.
Phương thức HTTP
PATCH
URL yêu cầu
https://www.googleapis.com/fitness/v1/users/me/dataSources/datasource.dataStreamId/datasets/1574159699023000000-1574159699023000000
Nội dung yêu cầu
Để cho rõ ràng, phần nội dung JSON hiển thị bên dưới được chú thích bằng nhận xét để hiển thị
việc sử dụng hằng số trường sức khoẻ.
{
"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
}
]
}
]
}
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\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 }"]]