+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ wearComposeMaterial3 = "1.5.3"
wearOngoing = "1.1.0"
wearToolingPreview = "1.0.0"
webkit = "1.14.0"
wearInput = "1.2.0"

[libraries]
accompanist-adaptive = "com.google.accompanist:accompanist-adaptive:0.37.3"
Expand Down Expand Up @@ -198,6 +199,7 @@ play-services-wearable = { module = "com.google.android.gms:play-services-wearab
validator-push = { module = "com.google.android.wearable.watchface.validator:validator-push", version.ref = "validatorPush" }
wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
wear-compose-material3 = { module = "androidx.wear.compose:compose-material3", version.ref = "wearComposeMaterial3" }
androidx-wear-input = { group = "androidx.wear", name = "wear-input", version.ref = "wearInput" }

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
Expand Down
1 change: 1 addition & 0 deletions wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.media3.exoplayer)
implementation(libs.androidx.media3.ui)
implementation(libs.androidx.wear.input)
val composeBom = platform(libs.androidx.compose.bom)
implementation(composeBom)
androidTestImplementation(composeBom)
Expand Down
11 changes: 11 additions & 0 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
android:name="com.google.android.wearable.standalone"
android:value="true" />

<activity
android:name=".snippets.hardwarebuttons.HardwareButtonsActivity"
android:exported="true"
android:taskAffinity=""
android:theme="@android:style/Theme.DeviceDefault">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".snippets.m3.MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.wear.snippets.hardwarebuttons

import android.app.Activity
import android.content.Context
import android.util.Log
import android.view.KeyEvent
import androidx.activity.ComponentActivity
import androidx.wear.input.WearableButtons

class HardwareButtonsActivity : ComponentActivity() {
// [START android_wear_hardware_buttons_events]
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
return if (event?.repeatCount == 0) {
when (keyCode) {
KeyEvent.KEYCODE_STEM_1 -> {
Log.d(TAG, "KEYCODE_STEM_1 pressed")
true
}
KeyEvent.KEYCODE_STEM_2 -> {
Log.d(TAG, "KEYCODE_STEM_2 pressed")
true
}
else -> {
super.onKeyDown(keyCode, event)
}
}
} else {
super.onKeyDown(keyCode, event)
}
}
// [END android_wear_hardware_buttons_events]

fun hardwareButtonsCount(context: Context, activity: Activity) {
// [START android_wear_hardware_buttons_count]
val count = WearableButtons.getButtonCount(context)

if (count > 1) {
Log.d(TAG, "More than one button available")
}

val buttonInfo = WearableButtons.getButtonInfo(
activity,
KeyEvent.KEYCODE_STEM_1
)

if (buttonInfo == null) {
// KEYCODE_STEM_1 is unavailable
Log.d(TAG, "KEYCODE_STEM_1 not available")
} else {
// KEYCODE_STEM_1 is present on the device
Log.d(TAG, "KEYCODE_STEM_1 is present on the device")
}
// [END android_wear_hardware_buttons_count]
}
}
private const val TAG = "HardwareButtons"
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载