public static class StaticPreviewDataParser


Parses static complication preview data from a provider's AndroidManifest.xml metadata.

This utility is used to extract non-dynamic complication data that can be used for rendering the complication previews. This allows a preview to be shown without needing to bind to the complication provider service, which improves performance.

The data is sourced from an XML resource file that is linked via a <meta-data> tag within the complication provider service's declaration in the manifest.

Summary

Public fields

static @NonNull StaticPreviewDataParser

Public methods

static final PreviewData
@RequiresApi(value = 33)
parsePreviewData(
    @NonNull Context context,
    @NonNull ComponentName providerComponent
)

Parses all available static preview data from a provider's metadata declared in its AndroidManifest.xml.

Public fields

INSTANCE

Added in 1.3.0-beta01
public static @NonNull StaticPreviewDataParser INSTANCE

Public methods

parsePreviewData

Added in 1.3.0-beta01
@RequiresApi(value = 33)
public static final PreviewData parsePreviewData(
    @NonNull Context context,
    @NonNull ComponentName providerComponent
)

Parses all available static preview data from a provider's metadata declared in its AndroidManifest.xml.

This method looks for a <meta-data> tag with the key com.google.android.wearable.complications.STATIC_PREVIEW_DATA within the service definition of the specified providerComponent. The value of this tag should be a reference to an XML resource containing static preview data definitions for each supported type.

Example Manifest Declaration:

<service
android
:name=".MyComplicationProviderService"
android:exported="true"
android:label="@string/complication_provider_label"
android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER">

<meta-data
android
:name="com.google.android.wearable.comulations.STATIC_PREVIEW_DATA"
android:resource="@xml/my_complication_preview" />

</service>

Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no application with the given package name.

Throws {@link java.lang.SecurityException} if the Context requested can not be loaded into the caller's process for security reasons (see {@link Context#CONTEXT_INCLUDE_CODE} for more information}.

Parameters
@NonNull Context context

The Context of the calling application (e.g., the watch face). It is used to access the PackageManager.

@NonNull ComponentName providerComponent

The ComponentName of the complication provider service from which to parse the preview data.

Returns
PreviewData

A PreviewData object if the metadata is found and successfully parsed. Returns null if the metadata tag is not present, if the resource ID is invalid, or if any error occurs during parsing.