# StaticPreviewDataParser

Artifact: [androidx.wear.watchface:watchface-complications-data](https://developer.android.com/jetpack/androidx/releases/wear-watchface) [View Source](https://cs.android.com/search?q=file:androidx/wear/watchface/complications/data/parser/StaticPreviewDataParser.kt+class:androidx.wear.watchface.complications.data.parser.StaticPreviewDataParser) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

*** ** * ** ***


```
public static class StaticPreviewDataParser
```

<br />

*** ** * ** ***

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 @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/parser/StaticPreviewDataParser` | `https://developer.android.com/reference/androidx/wear/watchface/complications/data/parser/StaticPreviewDataParser#INSTANCE()` |

| ### Public methods |
|---|---|
| `static final https://developer.android.com/reference/androidx/wear/watchface/complications/data/parser/PreviewData` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 33) https://developer.android.com/reference/androidx/wear/watchface/complications/data/parser/StaticPreviewDataParser#parsePreviewData(android.content.Context,android.content.ComponentName)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html 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](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
public static @NonNull StaticPreviewDataParser INSTANCE
```

## Public methods

### parsePreviewData

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
@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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | The `Context` of the calling application (e.g., the watch face). It is used to access the `PackageManager`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html providerComponent` | The `ComponentName` of the complication provider service from which to parse the preview data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/wear/watchface/complications/data/parser/PreviewData` | A `https://developer.android.com/reference/androidx/wear/watchface/complications/data/parser/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. |