เขียนข้อมูลความดันโลหิต
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แอปของคุณสามารถบันทึกข้อมูลความดันโลหิตโดยการเขียนไปยัง com.google.blood_pressure
ประเภทข้อมูล ในประเภทข้อมูลนี้ จุดข้อมูลแต่ละจุดจะแสดงเหตุการณ์เดียวที่เกิดขึ้นทันที
ที่อ่านค่าความดันโลหิต จุดข้อมูลมีฟิลด์สำหรับค่า Sytroid และ
ความดันไดแอสโตลิก ตำแหน่งของร่างกายระหว่างที่อ่านค่า และตำแหน่งในร่างกาย
ที่มีการวัดค่า
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
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"
}
}
การตอบกลับ
หากสร้างแหล่งข้อมูลสำเร็จ คุณจะได้รับ HTTP ของ 200 OK
รหัสสถานะการตอบสนอง เนื้อหาการตอบกลับมีการแสดงไฟล์ JSON ของ
แหล่งข้อมูล รวมถึงพร็อพเพอร์ตี้ datasource.dataStreamId
ใช้รหัสนี้
เป็น dataSourceId
เพื่อเพิ่มข้อมูล
เพิ่มข้อมูลความดันโลหิต
เพิ่มข้อมูลโดยการสร้างจุดข้อมูลประเภท com.google.blood_pressure
เมธอด HTTP
PATCH
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 Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 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 }"]]