[[["容易理解","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,["# Weather data in the Watch Face Format\n\nSince version 2, the Watch Face Format includes support for weather data.\nThis data covers a range of metrics and timeframes, from the current conditions\nto hourly and daily forecasts.\n\nWeather is accessed using *expressions* . For example, to show the current\nweather conditions in a [`\u003cText\u003e`](/training/wearables/wff/group/part/text/text) element, use an expression similar to\nthe following: \n\n \u003cText\u003e\n \u003cFont family=\"SYNC_TO_DEVICE\" size=\"32\"\u003e\n \u003cTemplate\u003eToday's weather: %s\n \u003cParameter expression=\"[WEATHER.CONDITION_NAME]\"/\u003e\n \u003c/Template\u003e\n \u003c/Font\u003e\n \u003c/Text\u003e\n\nAvailability\n------------\n\nWatch faces should always check the `[WEATHER.IS_AVAILABLE]` value before\naccessing other members of the `[WEATHER.*]` object: \n\n \u003cCondition\u003e\n \u003cExpressions\u003e\n \u003cExpression name=\"is_weather_available\"\u003e[WEATHER.IS_AVAILABLE]\u003c/Expression\u003e\n \u003c/Expressions\u003e\n \u003cCompare expression=\"is_weather_available\"\u003e\n \u003c!-- Weather is available, so show the weather data. --\u003e\n \u003c/Compare\u003e\n \u003cDefault\u003e\n \u003c!-- Weather isn't available, so show an appropriate message. --\u003e\n \u003c/Default\u003e\n \u003c/Condition\u003e\n\nAdditionally, the watch face should check `[WEATHER.IS_ERROR]`, which indicates\nan error in loading weather data.\n\nNote that `[WEATHER.IS_AVAILABLE]` and `[WEATHER.IS_ERROR]` can both be true,\nwhere the data is stale and attempts to refresh the data failed. In such cases,\nthe available weather can be shown, along with an indicator to show that there\nwas an error in fetching new data.\n\nFreshness of data\n-----------------\n\nThe timestamp of the available data can be accessed using\n`[WEATHER.LAST_UPDATED]` which is a Unix epoch timestamp in milliseconds.\n\nThis value can be formatted using the [`icuText(,)`](/training/wearables/wff/common/attributes/arithmetic-expression#functions) method to obtain a\nhuman-readable representation, as demonstrated in the [weather sample](https://github.com/android/wear-os-samples/tree/main/WatchFaceFormat/Weather).\n\nWeather conditions\n------------------\n\nThe current conditions are available in `[WEATHER.CONDITION]`, with a\nhuman-readable version in `[WEATHER.CONDITION_NAME]`.\n\nThe values for `[WEATHER.CONDITION]` can be seen in [data sources](/training/wearables/wff/common/attributes/source-type). For\nexample, `4` represents `HEAVY_RAIN`.\n| **Note:** If the watch face represents the current conditions, we strongly recommend you handle **all** potential values in the `[WEATHER.CONDITION]` enumeration.\n\nOther metrics\n-------------\n\nWatch Face Format provides a range of additional metrics, such as\n`[WEATHER.TEMPERATURE]` and `[WEATHER.UV_INDEX]`. For the full details\nof available metrics, including units and data types, visit the\n[data sources](/training/wearables/wff/common/attributes/source-type) reference page.\n\nHourly and daily forecasts\n--------------------------\n\nYou can access forecast conditions for a specific hour or day in the future\nas follows:\n\n- `[WEATHER.HOURS.1.CONDITION]` - the forecast conditions 1 hour from now.\n- `[WEATHER.DAYS.2.CONDITION]` - the forecast conditions 2 days from now.\n\nHourly data can be available up to 8 hours ahead, and daily data up to 5 days\nahead. However, the watch face should always check for the availability of\nforecast data. A different range of hours or days might be available at\ndifferent times, or different devices. For example, to check whether forecast\ndata is available for 1 hour from now, use `[WEATHER.HOURS.1.IS_AVAILABLE]`.\n| **Note:** If your watch face renders a `CONDITION` for forecast data, we strongly recommend that you handle **all** potential values in the `CONDITION` enumeration.\n\nDaily and hourly forecasts also feature a range of metrics, such as\n`[WEATHER.HOURS.\u003cN\u003e.TEMPERATURE]` and\n`[WEATHER.DAYS.\u003cN\u003e.CHANCE_OF_PRECIPITATION]`. For the full details\nof available metrics, including units and data types, visit the\n[data sources](/training/wearables/wff/common/attributes/source-type) reference page.\n\nTesting with weather data\n-------------------------\n\nTo obtain weather data, the Wear OS device must be aware of the device location.\n\nTo conserve power, the watch doesn't use the onboard GPS sensor to\ndetermine a location for the weather forecast, and instead relies on location\nfrom a connected handheld device or from available networks.\n\nTo make location data available for testing, do one of the following:\n\n- [Pair your Wear OS emulator](/training/wearables/get-started/connect-phone) with a physical or emulator phone.\n- Simulate location through the following adb command:\n\n adb unroot\n adb shell cmd location set-location-enabled true\n adb root\n adb shell appops set 0 android:mock_location allow\n adb shell cmd location providers add-test-provider gps\n adb shell cmd location providers set-test-provider-enabled gps true\n adb shell cmd location providers set-test-provider-location gps --location 37.773972,-122.431297\n\nFurther details\n---------------\n\nFor a complete example of accessing and rendering weather data, see the\n[GitHub sample](https://github.com/android/wear-os-samples/tree/main/WatchFaceFormat/Weather).\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Change focus behavior](/develop/ui/compose/touch-input/focus/change-focus-behavior)\n- [Side-effects in Compose](/develop/ui/compose/side-effects)\n- [AGSL Quick Reference](/develop/ui/views/graphics/agsl/agsl-quick-reference)"]]