WearWidgetProviderInfo

class WearWidgetProviderInfo


Describes the metadata for a Wear Widget provider.

The fields in this class correspond to the fields in the <wearwidget-provider> xml tag.

For example, the AndroidManifest.xml would contain:

<service
android:name=".MyWidgetService"
android:exported="true">
<meta-data
android:name="androidx.glance.wear.widget.provider"
android:resource="@xml/my_widget_info" />
</service>

And res/xml/my_widget_info.xml would contain:

<wearwidget-provider
label="@string/widget_label"
description="@string/widget_description"
icon="@drawable/widget_icon"
preferredType="@integer/glance_wear_container_type_small" >

<container
type="@integer/glance_wear_container_type_small"
previewImage="@drawable/small_preview"/>

<container
type="@integer/glance_wear_container_type_large"
previewImage="@drawable/large_preview"
label="@string/large_container_label_override" />

</wearwidget-provider>

For container types, see ContainerInfo.ContainerType. In XML metadata for your widgets, these should be referenced by using the public integer resources @integer/glance_wear_container_type_large and @integer/glance_wear_container_type_small. These correspond to the integer constants ContainerInfo.CONTAINER_TYPE_LARGE and ContainerInfo.CONTAINER_TYPE_SMALL.

Summary

Public companion functions

WearWidgetProviderInfo
parseFromService(context: Context, providerService: ComponentName)

Parses a WearWidgetProviderInfo from the metadata of a service.

Public properties

String?

The intent action to launch an activity for configuring the widget.

List<ContainerInfo>

The list of ContainerInfo supported for this widget provider.

String

The description of this widget.

String

The name of the group this widget provider is associated with.

Int

The resource id of the icon for this widget.

String

The label of this widget.

Int

The preferred Container Type to use for a widget instance when type is not specified when adding a widget.

ComponentName

The ComponentName of this widget provider.

Map<StringString>

Any unrecognised attributes during the XML parsing of the provider info.

Public companion functions

parseFromService

Added in 1.0.0-alpha01
fun parseFromService(context: Context, providerService: ComponentName): WearWidgetProviderInfo

Parses a WearWidgetProviderInfo from the metadata of a service.

The metadata with name androidx.glance.wear.widget.provider should reference an XML resource with the provider info.

If not present, the values for label, description and icon are taken from the attributes.

Parameters
context: Context

The Context to use for resolving resources and package manager.

providerService: ComponentName

The ComponentName of the widget provider service.

Throws
android.content.pm.PackageManager.NameNotFoundException

if the meta-data resource is not found or the provider service is not found.

org.xmlpull.v1.XmlPullParserException

if there is an error parsing the XML resource or if this is not a valid provider info, for example: - No <container> tags are defined. - Multiple <container> tags have the same type. - Invalid resource IDs. - Using CONTAINER_TYPE_FULLSCREEN which is not supported for widgets.

Public properties

configIntentAction

Added in 1.0.0-alpha01
val configIntentActionString?

The intent action to launch an activity for configuring the widget. This can be null if no configuration is needed.

containers

Added in 1.0.0-alpha01
val containersList<ContainerInfo>

The list of ContainerInfo supported for this widget provider. Each element represents a supported type.

description

Added in 1.0.0-alpha01
val descriptionString

The description of this widget.

group

Added in 1.0.0-alpha01
val groupString

The name of the group this widget provider is associated with. Widget providers in the same group represent the same widget on the device. Only one provider service should be enabled at a time for a given group. This can be used to replace which provider service is associated with a widget on the device. Defaults to the fully qualified name of the provider service.

icon

Added in 1.0.0-alpha01
val iconInt

The resource id of the icon for this widget.

label

Added in 1.0.0-alpha01
val labelString

The label of this widget.

preferredContainerType

Added in 1.0.0-alpha01
val preferredContainerTypeInt

The preferred Container Type to use for a widget instance when type is not specified when adding a widget. This can be used when this provider is replacing a legacy Wear Tile provider. See ContainerInfo.

providerService

Added in 1.0.0-alpha01
val providerServiceComponentName

The ComponentName of this widget provider.

unrecognisedAttributes

Added in 1.0.0-alpha01
val unrecognisedAttributesMap<StringString>

Any unrecognised attributes during the XML parsing of the provider info.