Wear OS의 동적 표현식
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Wear OS는 카드 및 정보 표시에 표시되는 정보의 동적 업데이트를 지원합니다.
동적 표현식을 사용하면 카드 또는 정보 표시와 같은 앱 표면에 표시되는 데이터를 특정 데이터 소스에 결합할 수 있습니다. 이러한 데이터 소스의 예로는 플랫폼이 읽을 수 있는 심박수 데이터가 있습니다. 이 결합을 설정하고 나면 시스템이 카드 및 정보 표시의 데이터를 자동으로 업데이트합니다.
동적 데이터 결합 만들기
동적 데이터 결합을 만들려면 동적 데이터 유형을 사용하는 변수를 정의합니다. 사용하려는 데이터 스트림에 이 변수를 연결합니다.
예를 들어, 다음 코드 스니펫에서 볼 수 있듯이 시스템 시계 및 건강 정보와 관련된 값을 가져올 수 있습니다.
Kotlin
val systemTime = DynamicInstant.platformTimeWithSecondsPrecision()
val steps: DynamicInt32 = PlatformHealthSources.dailySteps()
Java
DynamicInstant systemTime = DynamicInstant.platformTimeWithSecondsPrecision();
DynamicInt32 steps = PlatformHealthSources.dailySteps();
다음 스니펫과 같이 상수 표현식에서 동적 값을 만들고 동적 값에 대해 산술 연산을 실행할 수도 있습니다.
Kotlin
val dynamicValue = DynamicInt32.constant(1).plus(2)
Java
DynamicInt32 dynamicValue = DynamicInt32.constant(1).plus(2)
가능한 동적 데이터 유형 목록
Wear OS는 다음과 같은 동적 데이터 유형을 지원합니다.
다음과 같은 기본 제공 기능을 사용하여 데이터 유형을 변환할 수도 있습니다.
DynamicInt32
는 format()
을 사용하여 DynamicString
으로의 변환을 지원합니다.
DynamicDuration
을 사용하면 특정 부분(예: 지속 시간의 초)을 DynamicInt32
객체로 추출할 수 있습니다.
각 화면에서 제한된 수의 동적 표현식 사용
시스템에는 특정 화면에서 동시에 처리할 수 있는 동적 표현식의 수에 제한이 있습니다. 추가 동적 표현식은 정적 값으로 변환됩니다.
Wear OS는 상수 표현식도 동적 표현식으로 간주합니다. 예를 들어, 다음 코드 스니펫에는 4개의 동적 표현식이 있습니다.
plus()
연산.
animate()
연산.
constant(1)
표현식.
plus()
동적 표현식의 2
값으로 암시되는 constant(2)
표현식.
DynamicInt32.constant(1).plus(2).animate()
드림
추천 서비스
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Dynamic expressions in Wear OS\n\nWear OS supports dynamic updates to information that appears in your [tiles](/training/wearables/tiles)\nand [complications](/training/wearables/tiles/complications).\n\nUsing dynamic expressions, you can bind data that appears on a surface of your\napp--such as a tile or complication--to a particular data source. An example of\nsuch a data source is heart rate data that the platform can read. After you've\nestablished this binding, the system updates the data in your tiles and\ncomplications automatically.\n\nCreate dynamic data bindings\n----------------------------\n\nTo create a dynamic data binding, define a variable that uses a\n[dynamic data type](#data-types). Associate this variable with the data stream that you\nwant to use.\n\nFor example, you can fetch values related to the system clock and health\ninformation, as shown in the following code snippet.\n| **Note:** To access the data in [`PlatformHealthSources`](/reference/androidx/wear/protolayout/expression/PlatformHealthSources), you must [request a\nruntime permission](/training/permissions/requesting) in your app. \n\n### Kotlin\n\n```kotlin\nval systemTime = DynamicInstant.platformTimeWithSecondsPrecision()\nval steps: DynamicInt32 = PlatformHealthSources.dailySteps()\n```\n\n### Java\n\n```java\nDynamicInstant systemTime = DynamicInstant.platformTimeWithSecondsPrecision();\nDynamicInt32 steps = PlatformHealthSources.dailySteps();\n```\n\nYou can also create dynamic values from constant expressions and perform\narithmetic operations on any dynamic value, as shown in the following snippet: \n\n### Kotlin\n\n```kotlin\nval dynamicValue = DynamicInt32.constant(1).plus(2)\n```\n\n### Java\n\n```java\nDynamicInt32 dynamicValue = DynamicInt32.constant(1).plus(2)\n```\n\n### List of possible dynamic data types\n\nWear OS supports the following dynamic data types:\n\n- [`DynamicBool`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicBool)\n- [`DynamicColor`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicColor)\n- [`DynamicDuration`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicDuration)\n- [`DynamicFloat`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicFloat)\n- [`DynamicInstant`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicInstant)\n- [`DynamicInt32`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicInt32)\n- [`DynamicString`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicString)\n\nIn addition, you can transform the data type using built-in capabilities, such\nas the following:\n\n- `DynamicInt32` supports conversion to a `DynamicString` using [`format()`](/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicInt32#format()).\n- `DynamicDuration` lets you extract specific parts, such as the seconds part of a duration, as `DynamicInt32` objects.\n\nUse a limited number of dynamic expressions on each screen\n----------------------------------------------------------\n\nThe system has a limit on the number of dynamic expressions that it can process\nsimultaneously on a particular screen. The system converts any additional\ndynamic expressions to static values.\n\nWear OS considers constant expressions to be dynamic expressions, too. For\nexample, the following code snippet contains 4 dynamic expressions:\n\n1. The `plus()` operation.\n2. The `animate()` operation.\n3. The `constant(1)` expression.\n4. The `constant(2)` expression, which is implied by the value `2` in the `plus()` dynamic expression.\n\n DynamicInt32.constant(1).plus(2).animate()\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Migrate to ProtoLayout namespaces](/training/wearables/tiles/migrate-to-protolayout)\n- [Side-effects in Compose](/develop/ui/compose/side-effects)\n- [AGSL Quick Reference](/develop/ui/views/graphics/agsl/agsl-quick-reference)"]]