object 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 functions

PreviewData?
@RequiresApi(value = 33)
parsePreviewData(context: Context, providerComponent: ComponentName)

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

Public functions

parsePreviewData

Added in 1.3.0-beta01
@RequiresApi(value = 33)
fun parsePreviewData(context: Context, providerComponent: ComponentName): PreviewData?

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
context: Context

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

providerComponent: ComponentName

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.