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 |
Public properties |
|
|---|---|
String? |
The intent action to launch an activity for configuring the widget. |
List<ContainerInfo> |
The list of |
String |
The description of this widget. |
String |
The name of the group this widget provider is associated with. |
@DrawableRes 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 |
Map<String, String> |
Any unrecognised attributes during the XML parsing of the provider info. |
Public companion functions
parseFromService
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
| Parameters | |
|---|---|
context: Context |
The |
providerService: ComponentName |
The |
| Throws | |
|---|---|
PackageManager.NameNotFoundException |
if the meta-data resource is not found or the provider service is not found. |
XmlPullParserException |
if there is an error parsing the XML resource or if this is not a valid provider info, for example: - No |
Public properties
configIntentAction
val configIntentAction: String?
The intent action to launch an activity for configuring the widget. This can be null if no configuration is needed.
containers
val containers: List<ContainerInfo>
The list of ContainerInfo supported for this widget provider. Each element represents a supported type.
group
val group: String
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.
This attribute is only used on devices on API version 37 and above. For backwards compatibility with services being used on older devices, the default value of the fully qualified name of the older service should be used.
preferredContainerType
val preferredContainerType: Int
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
val providerService: ComponentName
The ComponentName of this widget provider.
unrecognisedAttributes
val unrecognisedAttributes: Map<String, String>
Any unrecognised attributes during the XML parsing of the provider info.