Sdk

public final class Sdk
extends Object

java.lang.Object
   ↳ com.google.wear.Sdk


The Wear SDK provides developers with a new way to access Wear specific platform APIs.

Wear platform updates (and associated API changes) happen more frequently than Android's API release schedule via platform feature drops - as a result, developers should take note of the recommended methods which can help determine platform API availability/compatibility - ensuring that they are always targeting the correct version in their code.

Wear SDK users should make use of the following Android version/feature constructs:

  • android.os.Build.VERSION.SDK_INT The Wear OS platform is built upon the Android platform. As such, any required checks for platform API level should reference this value. Likewise, any API introduced in a new Android release can be assumed to be present in the Wear OS version built upon the same (only exception being cases where the Android Compatibility Definition Document precludes the availability of APIs/features on watches).
  • Sdk.hasApiFeature(String apiFeature) Using this method, developers can qualify changes to API that may have occurred between Android platform API updates (i.e. VERSION.isIncrementalRelease() is true) as a platform API feature drop.

When new APIs are added, developers should start by checking the documentation to see which platform API level or API feature introduced the API. Once a developer has determined the point of introduction, they can safely check for the availability of the API in their app before trying to use it so as to ensure compatibility.

Take for example a new API foo() which is introduced via the Wear SDK at Build.VERSION.SDK_INT == 33. Developers can use the familiar method to check API availability:

 public void doFoo() {
     if(Build.VERSION.SDK_INT >= 33) {
         foo();
     } else {
         // pre-foo compat
     }
 }

Summary

Nested classes

class Sdk.VERSION

Version constants for Wear SDK used to determine API availability/compatibility. 

class Sdk.VERSION_CODES

The set of known Wear SDK version codes:

 

Constants

String FEATURE_WEAR_GESTURE_DETECTION

Feature indicating support for detecting user gestures like One Handed Gestures.

String FEATURE_WEAR_MATERIAL_3

Feature indicating support for the Material 3 design system on Wear.

String FEATURE_WEAR_TIRAMISU_QPR1_API

This constant was deprecated in API level 34.1. use ApiVersion VERSION_CODES.WEAR_TIRAMISU_1 instead.

String FEATURE_WEAR_TIRAMISU_QPR2_API

This constant was deprecated in API level 34.1. use ApiVersion VERSION_CODES.WEAR_TIRAMISU_2 instead.

String FEATURE_WEAR_TIRAMISU_QPR3_API

This constant was deprecated in API level 34.1. use ApiVersion VERSION_CODES.WEAR_TIRAMISU_3 instead.

String FEATURE_WEAR_TIRAMISU_QPR4_API

This constant was deprecated in API level 34.1. use ApiVersion VERSION_CODES.WEAR_TIRAMISU_4 instead.

Public methods

static <T> T getWearManager(Context context, Class<T> managerClazz)

Get a specific Wear service manager for a given service by name, similar to android.content.Context.getSystemService(Class) )}.

static <T> T getWearManager(Class<T> managerClazz)

This method was deprecated in API level 33.3. Use Sdk.getWearManager(Context,Class) instead.

static boolean hasApiFeature(String apiFeature)

Check the availability of a given Wear API feature, where features are associated with Wear feature drops - based on incremental platform releases.

static boolean isApiVersionAtLeast(WearApiVersion requiredWearApiVersion)

Check whether or not the current Wear API version is equal to or greater than the specified Wear API Version.

Inherited methods

Constants

FEATURE_WEAR_GESTURE_DETECTION

Added in API level 36
public static final String FEATURE_WEAR_GESTURE_DETECTION

Feature indicating support for detecting user gestures like One Handed Gestures.

Constant Value: "com.google.wear.feature.GESTURE_DETECTION"

FEATURE_WEAR_MATERIAL_3

Added in API level 36
public static final String FEATURE_WEAR_MATERIAL_3

Feature indicating support for the Material 3 design system on Wear.

Constant Value: "com.google.wear.feature.MATERIAL_3"

FEATURE_WEAR_TIRAMISU_QPR1_API

Added in version 33.2
Deprecated in API level 34.1
public static final String FEATURE_WEAR_TIRAMISU_QPR1_API

This constant was deprecated in API level 34.1.
use ApiVersion VERSION_CODES.WEAR_TIRAMISU_1 instead.

The first Wear API quarterly release based on the Android T platform (API level 33).

Constant Value: "com.google.wear.api.T_QPR1"

FEATURE_WEAR_TIRAMISU_QPR2_API

Added in version 33.2
Deprecated in API level 34.1
public static final String FEATURE_WEAR_TIRAMISU_QPR2_API

This constant was deprecated in API level 34.1.
use ApiVersion VERSION_CODES.WEAR_TIRAMISU_2 instead.

The second Wear API quarterly release based on the Android T platform (API level 33).

Constant Value: "com.google.wear.api.T_QPR2"

FEATURE_WEAR_TIRAMISU_QPR3_API

Added in version 33.3
Deprecated in API level 34.1
public static final String FEATURE_WEAR_TIRAMISU_QPR3_API

This constant was deprecated in API level 34.1.
use ApiVersion VERSION_CODES.WEAR_TIRAMISU_3 instead.

The third Wear API quarterly release based on the Android T platform (API level 33).

Constant Value: "com.google.wear.api.T_QPR3"

FEATURE_WEAR_TIRAMISU_QPR4_API

Added in version 33.4
Deprecated in API level 34.1
public static final String FEATURE_WEAR_TIRAMISU_QPR4_API

This constant was deprecated in API level 34.1.
use ApiVersion VERSION_CODES.WEAR_TIRAMISU_4 instead.

The fourth Wear API quarterly release based on the Android T platform (API level 33).

Constant Value: "com.google.wear.api.T_QPR4"

Public methods

getWearManager

Added in version 33.3
public static T getWearManager (Context context, 
                Class<T> managerClazz)

Get a specific Wear service manager for a given service by name, similar to android.content.Context.getSystemService(Class) )}. For example:

     AmbientManager ambientManager = Sdk.getWearManager(context, AmbientManager.class);
 

Parameters
context Context: any context from the calling app.

managerClazz Class: the class for the manager being requested e.g. AmbientManager.class.

Returns
T the corresponding Wear service manager or null if the service could not be found.

getWearManager

Added in version 33.2
Deprecated in API level 33.3
public static T getWearManager (Class<T> managerClazz)

This method was deprecated in API level 33.3.
Use Sdk.getWearManager(Context,Class) instead.

Get a specific Wear service manager for a given service by name, similar to android.content.Context.getSystemService(Class). For example:

     AmbientManager ambientManager = Sdk.getWearManager(AmbientManager.class);
 

Parameters
managerClazz Class: the class for the manager being requested e.g. AmbientManager.class.

Returns
T the corresponding Wear service manager or null if the service could not be found.

hasApiFeature

Added in version 33.2
public static boolean hasApiFeature (String apiFeature)

Check the availability of a given Wear API feature, where features are associated with Wear feature drops - based on incremental platform releases.

Clients can use @RequiresFeature(name = <apiFeature name>, enforcement = "com.google.wear.Sdk#hasApiFeature") to ensure that their code checks required API compatibility/availability.

Note: This API is intended only for use with granular system features provided via the Wear SDK. clients checking an overall API level should use isApiVersionAtLeast(WearApiVersion) to qualify based on a release.

Parameters
apiFeature String: the required API feature to check using the pre-defined constants provided by the SDK.
Value is one of the following:
Returns
boolean true if the system includes & supports the required feature, otherwise false.

isApiVersionAtLeast

Added in version 34.1
public static boolean isApiVersionAtLeast (WearApiVersion requiredWearApiVersion)

Check whether or not the current Wear API version is equal to or greater than the specified Wear API Version. Note Wear API versions are predefined constants, provided by the Wear SDK Sdk.VERSION_CODES.

Parameters
requiredWearApiVersion WearApiVersion: the Wear API version required by the caller, to be checked against the current Wear API version.

Returns
boolean true if the current Wear API version is equal to or greater than the required API version, otherwise false.