[[["易于理解","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"]],["最后更新时间 (UTC):2025-08-30。"],[],[],null,["**Figure 1.** A sample of network of nodes with handheld and Wear OS devices.\n\nThe Wearable Data Layer API, which is part of Google Play services, provides a\ncommunication channel between wearable devices (like smart watches) and\nconnected handheld devices (usually smartphones). It is a way to synchronize and\ntransfer data between the devices. \n**Note:** This API is only available on Wear OS watches and\npaired Android devices. For Wear OS watches paired with iOS phones, apps can\nquery other cloud-based APIs if internet connectivity is available. For more\ninformation on these other APIs, visit\n[Network access and sync on\nWear OS](/training/wearables/data/network-access). \n**Caution:** Because the data layer APIs are designed for\ncommunication between handhelds and wearables, these are the only APIs you can\nuse to set up communication between these devices. For example, don't try to\nopen low-level sockets to create a communication channel.\n\nCommon use cases\n\nThe Data Layer API is particularly useful for fitness and media use cases.\n\nFitness apps\n\nSending exercise data from Wear OS app to mobile app Fitness apps often need to\nwrite the exercise data captured by a watch to a mobile app or to [Health\nConnect](/health-and-fitness/guides/health-connect). If using the Data Layer API to transfer data, use a\n[message client](/training/wearables/data/client-types#message-client) to send exercise data from the Wear OS app to the mobile app\nin order to write to Health Connect.\n\nStream live data to the mobile device during a home workout\n\nA [common home workout scenario](https://medium.com/androiddevelopers/wear-os-home-workouts-with-health-services-b9951fa9e0dc) is streaming heart rate data from a Wear OS\ndevice to a mobile device and showing the user up-to-date heart rate information\non their mobile device's screen. To stream this data, use a [channel client](/training/wearables/data/client-types#channel-client).\n\nMedia apps\n\nTo control a media player through the action of pause/resume/start/end from the\nwatch to the phone, use a [message client](/training/wearables/data/client-types#message-client).\n\nOptions for communication\n\nData is transferred in one of the following ways:\n\n1. **Directly**, when there is an established Bluetooth connection between the Wear OS device and another device.\n2. **Over an available network**, such as LTE or Wi-Fi, using a network node on Google's servers as an intermediary.\n\nAll Data Layer clients may exchange data either using Bluetooth or using the\ncloud, depending on connections available to the devices. Assume that data\ntransmitted using Data Layer may at some point use Google-owned servers.\n\nBluetooth\n\nWhen devices are connected using Bluetooth, Data Layer uses this connection.\nThere is a single encrypted channel between the devices, using standard\nBluetooth encryption, managed by Google Play services.\n\nCloud\n\nData is automatically routed through Google Cloud when Bluetooth is unavailable.\nAll data transferred through Google Cloud is end-to-end encrypted.\n\nSecurity of communications\n\nGoogle Play services enforces the following restrictions to provide more secure\ncommunication between the app installed on a Wear OS device and the same app\ninstalled on a nearby handheld device:\n\n- The package name must match across devices.\n- The signature of the package must match across devices.\n\nNo other apps have access to the data regardless of connection type.\n\nSetup\n\nThe Wearable Data Layer API has the following dependencies:\n\n- The latest version of [Google Play services](https://developers.google.com/android).\n- A Wear OS device or Wear OS emulator.\n\nInclude the following dependency in the build.gradle file of your Wear module: \n\n dependencies {\n ...\n implementation(\"com.google.android.gms:play-services-wearable:19.0.0\")\n }\n\nFacilitate the initial pairing process\n\n[Horologist](https://github.com/google/horologist) provides several helper libraries on top of platform APIs.\nIt includes a [data layer library](https://google.github.io/horologist/datalayer-helpers-guide/) that helps establish a connection between\na mobile device and a Wear OS device. Additionally, it provides convenient APIs\nto do the following:\n\n- Install the app on the other device.\n- Launch the app on the other device.\n- Launch a specific activity on the other device.\n- Launch the companion app.\n\nAccess the data layer\n\nTo call the Data Layer API, use the [`Wearable`](https://developers.google.com/android/reference/com/google/android/gms/wearable/Wearable) class to get instances of\nthe various client classes, such as [`DataClient`](https://developers.google.com/android/reference/com/google/android/gms/wearable/DataClient) and [`MessageClient`](https://developers.google.com/android/reference/com/google/android/gms/wearable/MessageClient).\n\nFor more information, refer to the [DataLayer sample](https://github.com/android/wear-os-samples/tree/main/DataLayer).\n\nUse a minimal client\n\nTo create a client, see the following example code: \n\nKotlin \n\n```kotlin\nval dataClient: DataClient = Wearable.getDataClient(context)\n```\n\nJava \n\n```java\nDataClient dataClient = Wearable.getDataClient(context);\n```\n| **Caution:** Before using the Wearable Data Layer API, check that it's available on a device; otherwise, an exception occurs. Use the [`GoogleApiAvailability`](https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability) class, as implemented in [Horologist](https://github.com/google/horologist/blob/release-0.5.x/datalayer/core/src/main/java/com/google/android/horologist/data/WearableApiAvailability.kt#L29).\n\nThe context can be any valid Android context. If you are using the API within\nthe scope of an `Activity`, use the `getDataClient()` method of the `Wearable`\nclass. This lets certain interactions appear as dialogs rather than as\nnotifications, such as when the user is asked to update their version of Google\nPlay services.\n\nBy default, callbacks to listeners are made on the app's main UI thread. To have\ncallbacks made on a different thread, use a [`WearableOptions`](https://developers.google.com/android/reference/com/google/android/gms/wearable/Wearable.WearableOptions) object to\nspecify a custom `Looper`: \n\nKotlin \n\n```kotlin\nrunBlocking {\n Wearable.getDataClient(context, options)\n}\n```\n\nJava \n\n```java\nWearableOptions options = new WearableOptions.Builder().setLooper(myLooper).build();\nDataClient dataClient = Wearable.getDataClient(context, options);\n```\n\nFor more information, see the [`WearableOptions.Builder`](https://developers.google.com/android/reference/com/google/android/gms/wearable/Wearable.WearableOptions.Builder) reference.\n\nRecreate client instances as necessary\n\nWearable API clients, such as [`DataClient`](https://developers.google.com/android/reference/com/google/android/gms/wearable/DataClient) and [`MessageClient`](https://developers.google.com/android/reference/com/google/android/gms/wearable/MessageClient), are\ninexpensive to create. So instead of holding onto the clients, recreate them as\nyou need them, using the style that suits your app.\n\nThe client state, such as the set of registered listeners, is shared across all\nclients and is preserved if Google Play services is updated while an app is\nrunning."]]