wear-widgets
它能做什么
这个技能指导使用 Glance Wear 和 Remote Compose 构建、迁移和检查 Wear OS 小组件,涵盖小组件类、布局元素和状态。适合在智能手表上开发小组件的 Android 开发者。
适用场景
- ✓你想用 Glance Wear 和 Remote Compose 构建 Wear OS 小组件的时候。
- ✓你需要把 Wear OS 磁贴迁移为小组件的时候。
- ✓手表小组件需要按钮操作或修改本地状态的时候。
技能链接
https://github.com/android/skills/blob/main/wear/wear-widgets/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我创建一个 Wear OS 小组件,显示我的下一个日历事件,并带有一个标记为已完成的按钮。”
每周 5 个新技能,1 分钟读完。
工作原理
这个技能会确定最新的库版本,设置 SDK 和 Compose 要求,然后构建小组件服务和界面。它还会为小组件添加点击操作和本地状态。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Wear OS widgets use androidx.glance.wear (GlanceWearWidget and
GlanceWearWidgetService) with androidx.compose.remote (Remote Compose).
They serialize declarative UI and state documents to the watch host process.
Prerequisites and setup
Resolve library versions : Resolve the latest versions for
{GLANCE_WEAR_VERSION}(androidx.glance.wear),{COMPOSE_REMOTE_VERSION}(androidx.compose.remote), and{WEAR_COMPOSE_REMOTE_VERSION}(androidx.wear.compose.remote). Include-alpha,-beta, or-rcreleases when no stable version exists yet. Don't run./gradlew dependenciesto resolve versions:- Use an available dependency lookup tool if present.
- Otherwise, fetch the latest version from Google Maven metadata (Glance Wear metadata, Compose Remote metadata, Wear Compose Remote metadata).
SDK and Compose compiler requirements : Ask permission before modifying repo-wide Gradle files unless the user requested widget creation, tile migration, or dependency setup. Set
compileSdk = 37or higher and enablebuildFeatures { compose = true }. Keep the project's existing Android and Kotlin Gradle plugin declarations intact.dependencies { implementation("androidx.glance.wear:wear:{GLANCE_WEAR_VERSION}") implementation("androidx.glance.wear:wear-core:{GLANCE_WEAR_VERSION}") implementation("androidx.glance.wear:wear-tooling-preview:{GLANCE_WEAR_VERSION}") implementation("androidx.compose.remote:remote-creation-compose:{COMPOSE_REMOTE_VERSION}") implementation("androidx.compose.remote:remote-creation:{COMPOSE_REMOTE_VERSION}") implementation("androidx.compose.remote:remote-core:{COMPOSE_REMOTE_VERSION}") implementation("androidx.compose.remote:remote-tooling-preview:{COMPOSE_REMOTE_VERSION}") implementation("androidx.wear.compose.remote:remote-material3:{WEAR_COMPOSE_REMOTE_VERSION}") }
Codebase exploration
- Search the module for existing
TileService,Material3TileService, orGlanceWearWidgetimplementations,<service>entries inapp/src/main/AndroidManifest.xml, and@drawable/preview assets underapp/src/main/res/. - When migrating an existing tile or modifying an unfamiliar multi-module project, run
./gradlew :app:assembleDebugto verify baseline build health.
Workflow
Step 1: Configure AndroidManifest.xml and provider XML
Register the GlanceWearWidgetService subclass in
app/src/main/AndroidManifest.xml with the BIND_TILE_PROVIDER permission and
BIND_WIDGET_PROVIDER intent action. Attach <meta-data> pointing to an
@xml/ <wearwidget-provider> resource with SMALL and LARGE <container>
entries. When configuring the service, provider XML, or legacy TileService
migration, you MUST follow Widget service and manifest reference.
<service
android:name=".snippets.widget.skill.MyWidgetService"
android:exported="true"
android:permission="com.google.android.wearable.permission.BIND_TILE_PROVIDER">
<intent-filter>
<action android:name="androidx.glance.wear.action.BIND_WIDGET_PROVIDER" />
</intent-filter>
<meta-data
android:name="androidx.glance.wear.widget.provider"
android:resource="@xml/my_widget_info" />
</service>
Step 2: Implement GlanceWearWidget and GlanceWearWidgetService
Extend GlanceWearWidget and override provideWidgetData returning
WearWidgetDocument. Annotate the GlanceWearWidgetService subclass with
@AssociateWithGlanceWearWidget for static provider resolution:
// WRONG: Mobile GlanceAppWidget API (don't use on Wear OS)
class BrokenWidget : GlanceAppWidget() {
override suspend fun provideGlance(context: Context, id: GlanceId) {}
}
// CORRECT: Wear OS GlanceWearWidget + GlanceWearWidgetService
@AssociateWithGlanceWearWidget(MyWidget::class)
class MyWidgetService : GlanceWearWidgetService() {
override val widget: GlanceWearWidget = MyWidget()
}
class MyWidget : GlanceWearWidget() {
override suspend fun provideWidgetData(
context: Context,
params: WearWidgetParams,
): WearWidgetData =
WearWi
常见问题
它会自行修改我的 Gradle 文件吗?
除非你要求创建小组件或设置依赖,否则它在修改仓库范围的 Gradle 文件前会先征求你的同意。
它如何查找库版本?
它使用可用的查询工具或官方 Google Maven 元数据,而不是运行依赖命令。
它支持 alpha 或 beta 版本吗?
支持。如果还没有稳定版,这个技能可能会使用 alpha、beta 或候选发布版。
详情
作者的原始描述
Create, migrate, update, and verify Wear OS widgets using Glance Wear and Remote Compose in an Android project. Use this skill when implementing GlanceWearWidget, GlanceWearWidgetService, WearWidgetDocument, Remote Compose UI primitives (RemoteColumn, RemoteRow, RemoteBox, RemoteText, RemoteImage, RemoteButton), local state with rememberMutableRemoteInt and valueChange, click actions with pendingIntentAction, widget provider XML containers (SMALL and LARGE), rectangular widget picker PNG previews, or migrating legacy ProtoLayout TileService tiles to Wear OS widgets. Don't use for mobile home s
repo: android/skills
热度
- GitHub 星标
- 10k
- 排名
- #11940
- 许可证
- Apache-2.0
- 更新时间
- 2026/10/29
评论
- …
同一仓库的更多技能
agp-9-upgrade
10k帮你的智能体把 Android 应用升级到 Android Gradle Plugin 9,并处理其中的破坏性变更。不适用于多平台项目。
camerax
10k帮你的智能体使用 CameraX 构建 Android 相机功能,包括视频录制、硬件控制以及 ML Kit 和 Media3 效果。
android-for-cars-parked-apps
10k帮你的智能体把 Android 视频、游戏或浏览器应用调整为可在 Android Auto 和 Android Automotive 上以停放应用形式运行。
appfunctions
10k帮你的智能体在 Android 应用中找到关键工作流,并把它们暴露为 AI 智能体和语音命令可以运行的 AppFunctions。