Google is committed to advancing racial equity for Black communities. See how.

WearableButtonsProvider

interface WearableButtonsProvider
androidx.wear.input.WearableButtonsProvider

A provider interface to allow WearableButtons to query for information on the device's buttons from the platform. This exists to allow for the button provider to be switched out for testing, for example, by using androidx.wear.input.testing.TestWearableButtonsProvider.

Summary

Public methods
abstract IntArray?

Get the keycodes of available hardware buttons on device.

abstract Bundle
getButtonInfo(@NonNull context: Context, keycode: Int)

Returns a bundle containing the metadata of a specific button.

Public methods

getAvailableButtonKeyCodes

@Nullable abstract fun getAvailableButtonKeyCodes(@NonNull context: Context): IntArray?

Get the keycodes of available hardware buttons on device. This function based on key's locations from system property. This count includes the primary stem key as well as any secondary stem keys available.

Parameters
context Context: The context of the current activity
Return
IntArray? An int array of available button keycodes, or null if no keycodes could be read.

getButtonInfo

@NonNull abstract fun getButtonInfo(
    @NonNull context: Context,
    keycode: Int
): Bundle

Returns a bundle containing the metadata of a specific button. Currently, only location is supported. Use with com.google.android.wearable.input.WearableInputDevice#X_KEY and com.google.android.wearable.input.WearableInputDevice#Y_KEY. The key will not be present if the information is not available for the requested keycode.

The location returned is a Cartesian coordinate where the bottom left corner of the screen is the origin. The unit of measurement is in pixels. The coordinates do not take rotation into account and assume that the device is in the standard upright position.

Parameters
context Context: The context of the current activity
keycode Int: The keycode associated with the hardware button of interest
Return
Bundle A Bundle containing the metadata for the given keycode