[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Metadata requirements\n\n\u003e This guide is compatible with Health Connect version [1.1.0-alpha12](/jetpack/androidx/releases/health-connect#1.1.0-alpha12).\n\nThere are changes to metadata in Health Connect for\ndevelopers who choose to upgrade to release 1.1.0-alpha12.\n| **Warning:** Updating Jetpack versions without implementing these changes will break your Health Connect integration.\n\nLibrary information\n-------------------\n\nThe [Google Maven Android gradle plugin](/build/dependencies#google-maven) artifact ID\nidentifies the Health Connect library to which you will need to upgrade.\nAdd this Health Connect SDK dependency to your module-level\n`build.gradle` file: \n\n dependencies {\n implementation \"androidx.health.connect:connect-client:1.1.0-alpha12\"\n }\n\nMetadata changes\n----------------\n\nTwo metadata changes have been introduced to the **Health Connect Jetpack SDK**\nas of version 1.1.0-alpha12 to ensure that additional useful metadata\nexists in the ecosystem.\n\nYou are required to specify metadata details whenever\na `Record()` type object is instantiated.\n\nYou must specify one of four recording methods\nwhen writing data to **Health Connect**:\n\n| Recording method | Description |\n|-------------------------------------------|---------------------------------------------------------------------------|\n| `RECORDING_METHOD_UNKNOWN` | The recording method cannot be verified. |\n| `RECORDING_METHOD_MANUAL_ENTRY` | The user entered the data. |\n| `RECORDING_METHOD_AUTOMATICALLY_RECORDED` | A device or sensor recorded the data. |\n| `RECORDING_METHOD_ACTIVELY_RECORDED` | The user initiated the start or end of the recording session on a device. |\n\nFor example: \n\n StepsRecord(\n startTime \\= Instant.ofEpochMilli(1234L),\n startZoneOffset \\= null,\n endTime \\= Instant.ofEpochMilli(1236L),\n endZoneOffset \\= null,\n metadata \\= Metadata.manualEntry(),\n Count \\= 10,\n )\n\nYou are required to specify a device type for all\nautomatically and actively recorded data. Current device types include:\n\n| Device type | Description |\n|----------------------|-------------------------------------------|\n| `TYPE_UNKNOWN` | The device type is unknown. |\n| `TYPE_WATCH` | The device type is a watch. |\n| `TYPE_PHONE` | The device type is a phone. |\n| `TYPE_SCALE` | The device type is a scale. |\n| `TYPE_RING` | The device type is a ring. |\n| `TYPE_HEAD_MOUNTED` | The device type is a head-mounted device. |\n| `TYPE_FITNESS_BAND` | The device type is a fitness band. |\n| `TYPE_CHEST_STRAP` | The device type is a chest strap. |\n| `TYPE_SMART_DISPLAY` | The device type is a smart display. |\n\nFor example:\n\n`private val TEST_DEVICE = Device(type = Device.TYPE_PHONE)`\n\n### Snippets updated\n\nHealth Connect guides have been updated wherever new snippets are needed\nto adhere to the new metadata requirements. For some examples, refer to the\n[Write Data](/health-and-fitness/guides/health-connect/develop/write-data) page.\n\n### New metadata methods\n\nMetadata can no longer be directly instantiated, so use one of the\nfactory methods to get a new instance of metadata.\nEach function has three signature variants:\n\n- `activelyRecorded`\n\n - `fun activelyRecorded(device: Device): Metadata.`\n - `fun activelyRecorded(clientRecordId: String, clientRecordVersion: Long = 0, device: Device): Metadata`\n - `fun activelyRecordedWithId(id: String, device: Device): Metadata`\n- `autoRecorded`\n\n - `fun autoRecorded(device: Device): Metadata`\n - `fun autoRecorded(clientRecordId: String, clientRecordVersion: Long = 0, device: Device): Metadata`\n - `fun autoRecordedWithId(id: String, device: Device): Metadata`\n- `manualEntry`\n\n - `fun manualEntry(device: Device? = null): Metadata`\n - `fun manualEntry(clientRecordId: String, clientRecordVersion: Long = 0, device: Device? = null): Metadata`\n - `fun manualEntryWithId(id: String, device: Device? = null): Metadata`\n- `unknownRecordingMethod`\n\n - `fun unknownRecordingMethod(device: Device? = null): Metadata`\n - `fun unknownRecordingMethod(clientRecordId: String, clientRecordVersion: Long = 0, device: Device? = null): Metadata`\n - `fun unknownRecordingMethodWithId(id: String, device: Device? = null): Metadata`\n\nFor more information, see the [Android Open Source Project](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:health/connect/connect-client/src/main/java/androidx/health/connect/client/records/metadata/Metadata.kt).\n\n### Testing data\n\nUse the [Testing Library](/health-and-fitness/guides/health-connect/test/unit-tests) to mock expected metadata\nvalues: \n\n private val TEST_METADATA =\n Metadata.unknownRecordingMethod(\n clientRecordId = \"clientId\",\n clientRecordVersion = 1L,\n device = Device(type = Device.TYPE_UNKNOWN),\n ).populatedWithTestValues(id = \"test\")\n\nThis simulates the behavior of the Health Connect implementation,\nwhich automatically populates these values during record insertion.\n\nFor the testing library, you need to add this Health Connect SDK dependency to\nyour module-level `build.gradle` file: \n\n dependencies {\n testImplementation \"androidx.health.connect:connect-testing:1.0.0-alpha02\"\n }\n\nUpgrade the library\n-------------------\n\nThe main steps you need to perform are:\n\n1. Upgrade your library to 1.1.0-alpha12.\n\n2. When building the library, compilation errors will be thrown where\n new metadata is needed, so be sure to implement the necessary metadata changes\n whenever a `Record()` type object is instantiated. This\n should complete the migration."]]