사용자는 Wear OS 기기를 설정할 때 Wear OS 기기를 특정 휴대기기에 연결합니다. 사용자는 나중에 새 휴대기기를 구입하고 기존 Wear OS 기기를 이 새 휴대기기에 연결하기로 결정할 수도 있습니다. Wear OS 기기와 관련된 일부 데이터는 현재 연결된 휴대기기에 저장됩니다.
Wear OS 4부터는 사용자가 새 휴대기기에 연결할 때 Wear OS 데이터를 새 휴대기기로 전송할 수 있습니다. 데이터가 전송되면 자동으로 동기화됩니다.
사용자가 전송을 요청하면 웨어러블 데이터 영역이 하나의 휴대기기에 저장되어 있던 DataItem 객체를 다른 휴대기기로 전송합니다. 이를 통해 앱 사용자에게 원활한 환경을 제공할 수 있습니다.
이 문서에서는 이 시나리오를 지원하기 위해 Wear OS 앱 및 호환 모바일 앱을 구성하는 방법을 설명합니다.
준비
데이터 전송 프로세스는 데이터를 소유한 앱에 따라 DataItem 객체를 다르게 처리합니다.
Wear OS 앱이 소유한 객체
이러한 객체는 Wear OS 기기에 보존됩니다.
모바일 앱에서 소유한 객체
이러한 객체는 이전 기기에 보관처리됩니다. 그런 다음, 시스템은 보관처리된 데이터를 DataItemBuffer 객체로 패키징하고 이 데이터를 새 휴대기기에 설치된 모바일 앱으로 전달합니다.
보관 파일이 전달된 직후, 웨어러블 데이터 영역은 onNodeMigrated() 리스너를 호출합니다. Wear OS 기기에서 데이터를 쓸 때 앱에 알림을 보내는 방식과 유사합니다.
전송된 데이터 보존
전송된 DataItem 객체를 보존하는 것은 앱의 책임입니다.
데이터가 새 휴대기기로 전송되면 곧바로 보관 파일이 이전 기기에서 삭제됩니다.
다음 조건이 모두 충족되는지 확인하세요.
앱이 전송에 관여하는 두 휴대기기에 모두 설치되어 있습니다.
각 휴대기기에 설치된 모바일 앱의 패키지 서명이 일치합니다.
일치하지 않으면 보관처리된 DataItem 객체가 전달되지 않고 삭제됩니다.
이전 휴대기기에서 데이터 수신
이전 휴대기기에 보관처리된 데이터를 새 휴대기기에서 수신하려면 모바일 앱에서 WearableListenerService 클래스의 일부인 onNodeMigrated() 콜백을 구현해야 합니다. 그러려면 다음 단계를 완료하세요.
모바일 앱의 빌드 파일에 Google Play 서비스의 웨어러블 라이브러리 최신 버전에 관한 종속 항목을 포함합니다.
WearableListenerService를 확장하고 onNodeMigrated()를 재정의하는 서비스 클래스를 만듭니다.
Kotlin
classMyWearableListenerService:WearableListenerService(){valdataClient:DataClient=Wearable.getDataClient(this)privatefunshouldHandleDataItem(nodeId:String,dataItem:DataItem):Boolean{// Your logic herereturndataItem.uri.path?.startsWith("/my_feature_path/")==true}privatefunhandleDataItem(nodeId:String,dataItem:DataItem){valdata=dataItem.data?:returnvalpath=dataItem.uri.path?:return// Your logic hereif(data.toString().startsWith("Please restore")){dataClient.putDataItem(PutDataRequest.create(path).setData(data))}}overridefunonNodeMigrated(nodeId:String,archive:DataItemBuffer){valdataItemsToHandle=mutableListOf<DataItem>()for(dataIteminarchive){if(shouldHandleDataItem(nodeId,dataItem)){dataItemsToHandle.add(dataItem.freeze())}}// Callback stops automatically after 20 seconds of data processing.// If you think you need more time, delegate to a coroutine or thread.runBlocking{for(dataItemindataItemsToHandle){handleDataItem(nodeId,dataItem)}}}}
자바
publicclassMyWearableListenerServiceextendsWearableListenerService{privatefinalDataClientdataClient=Wearable.getDataClient(this);privatebooleanshouldHandleDataItem(StringnodeId,DataItemdataItem){// Your logic herereturnObjects.requireNonNull(dataItem.getUri().getPath()).startsWith("/my_feature_path/");}privateTask<DataItem>handleDataItem(StringnodeId,DataItemdataItem){byte[]data=dataItem.getData();Stringpath=dataItem.getUri().getPath();// Your logic hereif(data!=null && path!=null && Arrays.toString(data).startsWith("Please restore")){assertpath!=null;returndataClient.putDataItem(PutDataRequest.create(path).setData(data));}@OverridepublicvoidonNodeMigrated(@NonNullStringnodeId,DataItemBufferarchive){List<DataItem>dataItemsToHandle=newArrayList<>();for(DataItemdataItem:archive){if(shouldHandleDataItem(nodeId,dataItem)){dataItemsToHandle.add(dataItem.freeze());}}for(dataItemindataItemsToHandle){handleDataItem(nodeId,dataItem);}// Callback stops automatically after 20 seconds of data processing.// If you think you need more time, delegate to another thread.}}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-17(UTC)
[null,null,["최종 업데이트: 2025-08-17(UTC)"],[],[],null,["# Transfer Wear OS data to a new mobile device\n\nWhen users [set up a Wear OS device](https://support.google.com/wearos/answer/6056630), they connect the Wear OS device to a\nparticular mobile device. The user might later decide to get a new mobile device\nand connect their existing Wear OS device to this new mobile device. Some data\nrelated to a Wear OS device is stored on the currently-connected mobile device.\n\nStarting in Wear OS 4, when users connect to a new mobile device, they can\ntransfer Wear OS data to the new mobile device. Data is synced automatically\nwhen it's transferred.\n| **Note:** This process of transferring data to a new mobile device is different from [cloud backup and restore](/training/wearables/data/cloud-backup-restore), where the user restores data to a new Wear OS device.\n\nWhen the user requests a transfer, the [Wearable Data Layer](/training/wearables/data/data-layer) delivers\n[`DataItem`](https://developers.google.com/android/reference/com/google/android/gms/wearable/DataItem) objects, originally stored on one mobile device, to the other\nmobile device. This allows a seamless experience for users of your app.\n\nThis document describes how you can configure your Wear OS app, and its\ncompanion mobile app, to support this scenario.\n\nPreparation\n-----------\n\nThe data transfer process handles `DataItem` objects differently, depending on\nwhich app owns the data:\n\nObjects owned by the Wear OS app\n: These objects are preserved on the Wear OS device.\n\nObjects owned by the mobile app\n\n: These objects are archived on the old device. The system then packages the\n archived data into a [`DataItemBuffer`](https://developers.google.com/android/reference/com/google/android/gms/wearable/DataItemBuffer) object and delivers this data to the\n mobile app that's installed on the new mobile device.\n\n Immediately after the archive is delivered, the Wearable Data Layer invokes\n the [`onNodeMigrated()`](https://developers.google.com/android/reference/com/google/android/gms/wearable/WearableListenerService#onNodeMigrated(java.lang.String,%20com.google.android.gms.wearable.DataItemBuffer)) listener, similarly to how your app is notified\n when data is written by the Wear OS device.\n | **Note:** Data is transferred only if it's stored in the Wearable Data Layer.\n\nPreserve transferred data\n-------------------------\n\n| **Warning:** To avoid losing data, follow the guidance in this section.\n\nIt's your app's responsibility to preserve the transferred `DataItem` objects.\nShortly after the data is delivered to the new mobile device, the archive is\ndeleted off of the old device.\n\nMake sure each of the following conditions is true:\n\n1. Your app is installed on both mobile devices that are involved in the transfer.\n2. The mobile apps, installed on each mobile device, have package signatures that match.\n\nOtherwise, the archived `DataItem` objects aren't delivered and are instead\ndiscarded.\n\nReceive data from the old mobile device\n---------------------------------------\n\nTo receive data on the new mobile device that was archived on the old mobile\ndevice, your mobile app must implement the [`onNodeMigrated()`](https://developers.google.com/android/reference/com/google/android/gms/wearable/WearableListenerService#onNodeMigrated(java.lang.String,%20com.google.android.gms.wearable.DataItemBuffer)) callback,\npart of the `WearableListenerService` class. To do so, complete the following\nsteps:\n\n1. In your mobile app's build file, include a dependency on the latest version\n of the wearable library in Google Play services:\n\n ```groovy\n dependencies {\n ...\n implementation 'com.google.android.gms:play-services-wearable:19.0.0'\n }\n ```\n2. Declare and export the `WearableListenerService` in your app's\n manifest file:\n\n \u003cservice\n android:name=\".MyWearableListenerService\"\n android:exported=\"true\"\u003e\n \u003cintent-filter\u003e\n ...\n \u003caction android:name=\"com.google.android.gms.wearable.NODE_MIGRATED\" /\u003e\n \u003cdata android:scheme=\"wear\" /\u003e\n \u003c/intent-filter\u003e\n \u003c/service\u003e\n\n3. Create a service class which extends `WearableListenerService` and overrides\n `onNodeMigrated()`.\n\n **Caution:** To preserve system resources such as battery life, and to prevent ANRs, don't execute any power-demanding or time-consuming tasks in the `onNodeMigrated()` handler. \n\n ### Kotlin\n\n ```kotlin\n class MyWearableListenerService : WearableListenerService() {\n val dataClient: DataClient = Wearable.getDataClient(this)\n\n private fun shouldHandleDataItem(nodeId: String,\n dataItem: DataItem): Boolean {\n // Your logic here\n return dataItem.uri.path?.startsWith(\"/my_feature_path/\") == true\n }\n\n private fun handleDataItem(nodeId: String, dataItem: DataItem) {\n val data = dataItem.data ?: return\n val path = dataItem.uri.path ?: return\n // Your logic here\n if (data.toString().startsWith(\"Please restore\")) {\n dataClient.putDataItem(\n PutDataRequest.create(path).setData(data)\n )\n }\n }\n\n override fun onNodeMigrated(nodeId: String, archive: DataItemBuffer) {\n val dataItemsToHandle = mutableListOf\u003cDataItem\u003e()\n\n for (dataItem in archive) {\n if (shouldHandleDataItem(nodeId, dataItem)) {\n dataItemsToHandle.add(dataItem.freeze())\n }\n }\n\n // Callback stops automatically after 20 seconds of data processing.\n // If you think you need more time, delegate to a coroutine or thread.\n runBlocking {\n for (dataItem in dataItemsToHandle) {\n handleDataItem(nodeId, dataItem)\n }\n }\n }\n }\n ```\n\n ### Java\n\n ```java\n public class MyWearableListenerService extends WearableListenerService {\n private final DataClient dataClient = Wearable.getDataClient(this);\n\n private boolean shouldHandleDataItem(String nodeId, DataItem dataItem) {\n // Your logic here\n return Objects.requireNonNull(dataItem.getUri().getPath())\n .startsWith(\"/my_feature_path/\");\n }\n\n private Task\u003cDataItem\u003e handleDataItem(String nodeId, DataItem dataItem) {\n byte[] data = dataItem.getData();\n String path = dataItem.getUri().getPath();\n // Your logic here\n if (data != null && path != null && Arrays.toString(data)\n .startsWith(\"Please restore\")) {\n assert path != null;\n return dataClient.putDataItem(\n PutDataRequest.create(path).setData(data));\n }\n\n @Override\n public void onNodeMigrated(@NonNull String nodeId, DataItemBuffer archive) {\n List\u003cDataItem\u003e dataItemsToHandle = new ArrayList\u003c\u003e();\n\n for (DataItem dataItem : archive) {\n if (shouldHandleDataItem(nodeId, dataItem)) {\n dataItemsToHandle.add(dataItem.freeze());\n }\n }\n\n for (dataItem in dataItemsToHandle) {\n handleDataItem(nodeId, dataItem);\n }\n\n // Callback stops automatically after 20 seconds of data processing.\n // If you think you need more time, delegate to another thread.\n }\n }\n ```\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Integrate a Wear OS module](/health-and-fitness/guides/basic-fitness-app/integrate-wear-os)\n- [Conserve power and battery](/training/wearables/apps/power)"]]