# androidx.glance.appwidget

## Interfaces

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/PreviewSizeMode` | This marker interface determines which `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode`s can be used for preview compositions. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode` | Modes describing how the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` should handle size specification. |

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/CheckBoxColors` | Set of colors to apply to a CheckBox depending on the checked state. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` | Object handling the composition and the communication with `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html`. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetManager` | Manager for Glance App Widgets. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetReceiver` | `https://developer.android.com/reference/android/appwidget/AppWidgetProvider.html` using the given `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` to generate the remote views when needed. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceRemoteViews` | Object containing the information needed to generate a `https://developer.android.com/reference/android/widget/RemoteViews.html`. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceRemoteViewsService` | `https://developer.android.com/reference/android/widget/RemoteViewsService.html` to be connected to for a remote adapter that returns RemoteViews for lazy lists / grids. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/MyPackageReplacedReceiver` | Broadcast receiver handling updates after a package update. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/R` |   |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/R.bool` |   |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/R.layout` |   |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/RadioButtonColors` | Set of colors to apply to a RadioButton depending on the checked state. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/RemoteViewsCompositionResult` | Object containing the result from composition of `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceRemoteViews`. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode.Responsive` | The `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` provides a UI for a fixed set of sizes. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SwitchColors` | Set of colors to apply to a Switch depending on the checked state. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/UnmanagedSessionReceiver` | This receiver responds to lambda action clicks for unmanaged sessions (created by `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).runComposition(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,kotlin.collections.List,kotlin.Any,android.content.ComponentName)`). |

## Objects

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/CheckboxDefaults` | Contains the default values used by `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/CheckBox.composable#CheckBox(kotlin.Boolean,androidx.glance.action.Action,androidx.glance.GlanceModifier,kotlin.String,androidx.glance.text.TextStyle,androidx.glance.appwidget.CheckBoxColors,kotlin.Int)`. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/ProgressIndicatorDefaults` | Contains the default values used for `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/LinearProgressIndicator.composable#LinearProgressIndicator(kotlin.Float,androidx.glance.GlanceModifier,androidx.glance.unit.ColorProvider,androidx.glance.unit.ColorProvider)`. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/RadioButtonDefaults` | Contains the default values used by `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/RadioButton.composable#RadioButton(kotlin.Boolean,androidx.glance.action.Action,androidx.glance.GlanceModifier,kotlin.Boolean,kotlin.String,androidx.glance.text.TextStyle,androidx.glance.appwidget.RadioButtonColors,kotlin.Int)`. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode.Exact` | The `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` provides a UI for each size the App Widget may be displayed at. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode.Single` | The `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` provides a single UI. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SwitchDefaults` | Contains the default values used by `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/Switch.composable#Switch(kotlin.Boolean,androidx.glance.action.Action,androidx.glance.GlanceModifier,kotlin.String,androidx.glance.text.TextStyle,androidx.glance.appwidget.SwitchColors,kotlin.Int)`. |

## Annotations

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/ExperimentalGlanceRemoteViewsApi` |   |

## Composables

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/AndroidRemoteViews.composable` | Add `https://developer.android.com/reference/android/widget/RemoteViews.html` into a glance composition. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/CheckBox.composable` | Adds a check box view to the glance view. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/CircularProgressIndicator.composable` | Adds a circular progress indicator view to the glance view. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/LinearProgressIndicator.composable` | Adds an indeterminate linear progress indicator view to the glance view. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/RadioButton.composable` | Adds a radio button to the glance view. |
| `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/Switch.composable` | Adds a switch view to the glance view. |

## Top-level functions summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/ImageProvider` | `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#ImageProvider(android.net.Uri)(uri: https://developer.android.com/reference/android/net/Uri.html)` Image resource from a URI. |

## Extension functions summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier` | `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.GlanceModifier).appWidgetBackground()()` Define the current view as the background of the App Widget. |
| `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier` | `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.GlanceModifier).background(androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color)(day: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color, night: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color)` Apply a background color to the element this modifier is attached to. |
| `suspend https://developer.android.com/reference/android/widget/RemoteViews.html` | `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).compose(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,androidx.compose.ui.unit.DpSize,kotlin.Any)( context: https://developer.android.com/reference/android/content/Context.html, id: https://developer.android.com/reference/kotlin/androidx/glance/GlanceId, options: https://developer.android.com/reference/android/os/Bundle.html?, size: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize?, state: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html? )` Creates a snapshot of the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` content without running recomposition. |
| `suspend https://developer.android.com/reference/android/widget/RemoteViews.html` | `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).composeForPreview(android.content.Context,kotlin.Int,android.appwidget.AppWidgetProviderInfo)( context: https://developer.android.com/reference/android/content/Context.html, widgetCategory: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, info: https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html? )` Runs the composition in `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget#providePreview(android.content.Context,kotlin.Int)` one time and translate it to a `https://developer.android.com/reference/android/widget/RemoteViews.html`. |
| `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier` | `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.GlanceModifier).cornerRadius(androidx.compose.ui.unit.Dp)(radius: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp)` Adds rounded corners for the current view. |
| `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier` | `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.GlanceModifier).cornerRadius(kotlin.Int)(radius: @https://developer.android.com/reference/kotlin/androidx/annotation/DimenRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Adds rounded corners for the current view, using resources. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-nothing/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).provideContent(kotlin.Function0)( content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable @https://developer.android.com/reference/kotlin/androidx/glance/GlanceComposable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Provides `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).provideContent(kotlin.Function0)` to the Glance host, suspending until the Glance session is shut down. |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developer.android.com/reference/android/widget/RemoteViews.html>` | `@https://developer.android.com/reference/kotlin/androidx/glance/ExperimentalGlanceApi https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).runComposition(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,kotlin.collections.List,kotlin.Any,android.content.ComponentName)( context: https://developer.android.com/reference/android/content/Context.html, id: https://developer.android.com/reference/kotlin/androidx/glance/GlanceId, options: https://developer.android.com/reference/android/os/Bundle.html, sizes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize>?, state: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, lambdaReceiver: https://developer.android.com/reference/android/content/ComponentName.html )` Returns a Flow that, on collection, starts a composition session for this `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` and emits `https://developer.android.com/reference/android/widget/RemoteViews.html` for each result. |
| `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier` | `https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.GlanceModifier).selectableGroup()()` Use this modifier to group a list of RadioButtons together for accessibility purposes. |
| `suspend inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 35) <T : https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetReceiver> https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetManager.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidgetManager).setWidgetPreviews(androidx.collection.IntSet)( widgetCategories: https://developer.android.com/reference/kotlin/androidx/collection/IntSet )` Generate and publish the widget previews for a `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetReceiver` for the given set of `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidgetManager).setWidgetPreviews(androidx.collection.IntSet)`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).updateAll(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Update all App Widgets managed by the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` class. |
| `suspend inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<State : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget.https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).updateIf(android.content.Context,kotlin.Function1)( context: https://developer.android.com/reference/android/content/Context.html, predicate: (State) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Update all App Widgets managed by the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` class, if they fulfill some condition. |

## Top-level properties summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/ProvidableCompositionLocal<https://developer.android.com/reference/android/os/Bundle.html>` | `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#LocalAppWidgetOptions()` Option Bundle accessible when generating an App Widget. |

## Top-level functions

### ImageProvider

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/ImageProviders.kt+function:ImageProvider) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/glance#1.0.0)

```
fun ImageProvider(uri: Uri): ImageProvider
```

Image resource from a URI.

| Parameters |
|---|---|
| `uri: https://developer.android.com/reference/android/net/Uri.html` | The URI of the image to be displayed. |

## Extension functions

### GlanceModifier.appWidgetBackground

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/AppWidgetBackground.kt+function:appWidgetBackground) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/glance#1.0.0)

```
fun GlanceModifier.appWidgetBackground(): GlanceModifier
```

Define the current view as the background of the App Widget.

By definition, the background of the App Widget is the view with the id `@android:id/background`.

There can be only one view with this modifier in a given App Widget.

This modifier does not automatically set corner radius. To have these set for you, use the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/components/Scaffold.composable#Scaffold(androidx.glance.GlanceModifier,kotlin.Function0,androidx.glance.unit.ColorProvider,androidx.compose.ui.unit.Dp,kotlin.Function0)` component.

For more information about widget backgrounds, See the documentation on [Enable smoother transitions](https://developer.android.com/guide/topics/appwidgets/enhance#enable-smoother-transitions) and [Implement rounded corners](https://developer.android.com/guide/topics/appwidgets#rounded-corner) for details on why it is important to label a view as being the background, and why you will want to set the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.GlanceModifier).cornerRadius(androidx.compose.ui.unit.Dp)` of the same view.

### GlanceModifier.background

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/Background.kt+function:background) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/glance#1.2.0)

```
fun GlanceModifier.background(day: Color, night: Color): GlanceModifier
```

Apply a background color to the element this modifier is attached to. This will cause the element to paint the specified `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color` as its background, choosing `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.GlanceModifier).background(androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color)` or `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.GlanceModifier).background(androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color)` depending on the device configuration, which will fill the bounds of the element.

### GlanceAppWidget.compose

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/AppWidgetComposer.kt+function:compose)

```
suspend fun GlanceAppWidget.compose(
    context: Context,
    id: GlanceId = createFakeAppWidgetId(),
    options: Bundle? = null,
    size: DpSize? = null,
    state: Any? = null
): RemoteViews
```

Creates a snapshot of the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` content without running recomposition.

This runs the composition one time and translates it to `https://developer.android.com/reference/android/widget/RemoteViews.html`.

If a valid `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).compose(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,androidx.compose.ui.unit.DpSize,kotlin.Any)` is provided, this function will use the sizing values from the bound widget if using `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode.Exact` or `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode.Single`.

Only one instance of compose for a particular `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).compose(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,androidx.compose.ui.unit.DpSize,kotlin.Any)` may run at the same time. Calling compose concurrently with the same ID will succeed, but the first call will resume with an exception.

If you need to call compose concurrently, you can omit `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).compose(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,androidx.compose.ui.unit.DpSize,kotlin.Any)` so that a random fake ID will be used. Otherwise, call compose sequentially when using the same `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).compose(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,androidx.compose.ui.unit.DpSize,kotlin.Any)`.

### GlanceAppWidget.composeForPreview

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/AppWidgetComposer.kt+function:composeForPreview)

```
suspend fun GlanceAppWidget.composeForPreview(
    context: Context,
    widgetCategory: Int,
    info: AppWidgetProviderInfo? = null
): RemoteViews
```

Runs the composition in `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget#providePreview(android.content.Context,kotlin.Int)` one time and translate it to a `https://developer.android.com/reference/android/widget/RemoteViews.html`. This function can be used to test the preview layout of a GlanceAppWidget.

The value of `https://developer.android.com/reference/kotlin/androidx/glance/package-summary#LocalSize()` in the composition depends on the value of `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget#previewSizeMode()`:

If using SizeMode.Single (default), the composition will use the minimum size of the widget as determined by its `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#minHeight` and `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#minWidth`. If `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).composeForPreview(android.content.Context,kotlin.Int,android.appwidget.AppWidgetProviderInfo)` is null, then `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize#Zero()` will be used.

If using SizeMode.Responsive, the composition will use the provided sizes.

The given `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).composeForPreview(android.content.Context,kotlin.Int,android.appwidget.AppWidgetProviderInfo)` value should be a combination of `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#WIDGET_CATEGORY_HOME_SCREEN`, `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#WIDGET_CATEGORY_KEYGUARD`, or `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#WIDGET_CATEGORY_SEARCHBOX`.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | context to provide to `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget#providePreview(android.content.Context,kotlin.Int)` |
| `widgetCategory: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | widget category to provide to `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget#providePreview(android.content.Context,kotlin.Int)` |
| `info: https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html? = null` | the size of the composition is determined by the minimum width defined in this `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html` |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/widget/RemoteViews.html` | the preview composition translated to a `https://developer.android.com/reference/android/widget/RemoteViews.html` |

### GlanceModifier.cornerRadius

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/CornerRadius.kt+function:cornerRadius) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/glance#1.2.0)

```
fun GlanceModifier.cornerRadius(radius: Dp): GlanceModifier
```

Adds rounded corners for the current view.

Note: Only works on Android S+.

### GlanceModifier.cornerRadius

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/CornerRadius.kt+function:cornerRadius) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/glance#1.0.0)

```
fun GlanceModifier.cornerRadius(radius: @DimenRes Int): GlanceModifier
```

Adds rounded corners for the current view, using resources.

Note: Only works on Android S+.

### GlanceAppWidget.provideContent

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/GlanceAppWidget.kt+function:provideContent)

```
suspend fun GlanceAppWidget.provideContent(
    content: @Composable @GlanceComposable () -> Unit
): Nothing
```

Provides `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).provideContent(kotlin.Function0)` to the Glance host, suspending until the Glance session is shut down.

If this function is called concurrently with itself, the previous call will throw `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` and the new content will replace it. This function should only be called from `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget#provideGlance(android.content.Context,androidx.glance.GlanceId)`.

TODO: make this a protected member once b/206013293 is fixed.

### GlanceAppWidget.runComposition

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/AppWidgetComposer.kt+function:runComposition) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/glance#1.2.0)

```
@ExperimentalGlanceApi
fun GlanceAppWidget.runComposition(
    context: Context,
    id: GlanceId = createFakeAppWidgetId(),
    options: Bundle = Bundle(),
    sizes: List<DpSize>? = null,
    state: Any? = null,
    lambdaReceiver: ComponentName = ComponentName(context, UnmanagedSessionReceiver::class.java)
): Flow<RemoteViews>
```

Returns a Flow that, on collection, starts a composition session for this `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` and emits `https://developer.android.com/reference/android/widget/RemoteViews.html` for each result. The composition is closed when the flow is cancelled.

If a valid `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).runComposition(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,kotlin.collections.List,kotlin.Any,android.content.ComponentName)` is provided, this function will use the sizing values from the bound widget if using `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode.Exact` or `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/SizeMode.Single`.

Lambda actions and list views in the emitted `https://developer.android.com/reference/android/widget/RemoteViews.html` will continue to work while this is flow is running. This currently does not support resizing (you have to run the flow again with new `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).runComposition(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,kotlin.collections.List,kotlin.Any,android.content.ComponentName)`) or reloading the `https://developer.android.com/reference/kotlin/androidx/glance/state/GlanceStateDefinition` state value.

Note: In order to handle lambda actions correctly, only one instance of runComposition for a particular `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).runComposition(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,kotlin.collections.List,kotlin.Any,android.content.ComponentName)` may run at the same time. Calling runComposition concurrently with the same ID will succeed, but the first call will resume with an exception.

If you need to call runComposition concurrently, you can omit `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).runComposition(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,kotlin.collections.List,kotlin.Any,android.content.ComponentName)` so that a random fake ID will be used. Otherwise, call runComposition sequentially when using the same `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).runComposition(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,kotlin.collections.List,kotlin.Any,android.content.ComponentName)`.

By default, this function uses `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/UnmanagedSessionReceiver` as the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).runComposition(android.content.Context,androidx.glance.GlanceId,android.os.Bundle,kotlin.collections.List,kotlin.Any,android.content.ComponentName)` target to receive any lambda actions while this function is running. If you need to run this function in a non-default process, you can declare a sub-class of UnmanagedSessionReceiver in that process and pass its `https://developer.android.com/reference/android/content/ComponentName.html` here.

### GlanceModifier.selectableGroup

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/RadioButton.kt+function:selectableGroup) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/glance#1.0.0)

```
fun GlanceModifier.selectableGroup(): GlanceModifier
```

Use this modifier to group a list of RadioButtons together for accessibility purposes.

This modifier can only be used on a `https://developer.android.com/reference/kotlin/androidx/glance/layout/Row.composable#Row(androidx.glance.GlanceModifier,androidx.glance.layout.Alignment.Horizontal,androidx.glance.layout.Alignment.Vertical,kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/glance/layout/Column.composable#Column(androidx.glance.GlanceModifier,androidx.glance.layout.Alignment.Vertical,androidx.glance.layout.Alignment.Horizontal,kotlin.Function1)`. This modifier additonally enables the radio group effect, which automatically unselects the currently selected RadioButton when another is selected. When this modifier is used, an error will be thrown if more than one RadioButton has their "checked" value set to true.

### GlanceAppWidgetManager.setWidgetPreviews

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/GlanceAppWidgetManager.kt+function:setWidgetPreviews)

```
@RequiresApi(value = 35)
suspend inline fun <T : GlanceAppWidgetReceiver> GlanceAppWidgetManager.setWidgetPreviews(
    widgetCategories: IntSet = intSetOf(
            WIDGET_CATEGORY_HOME_SCREEN or WIDGET_CATEGORY_KEYGUARD or WIDGET_CATEGORY_SEARCHBOX
        )
): Int
```

Generate and publish the widget previews for a `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetReceiver` for the given set of `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidgetManager).setWidgetPreviews(androidx.collection.IntSet)`. Previews are generated from the layout provided by `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget#providePreview(android.content.Context,kotlin.Int)` on the widget connected to the given `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetReceiver` class. This receiver must be registered as an app widget provider in the application manifest.

Previews should be published during the initial setup phase or launch of your app. To avoid running this unnecessarily, you can see what previews are currently published for your provider by checking `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#generatedPreviewCategories`.

The preview composition is run for each value in the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidgetManager).setWidgetPreviews(androidx.collection.IntSet)` array. If your widget has the same layout across categories, you can combine all of the categories in a single value, e.g. `WIDGET_CATEGORY_HOME_SCREEN or WIDGET_CATEGORY_KEYGUARD or WIDGET_CATEGORY_SEARCHBOX`, which will call `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/package-summary#(androidx.glance.appwidget.GlanceAppWidget).composeForPreview(android.content.Context,kotlin.Int,android.appwidget.AppWidgetProviderInfo)` once and set the previews for all of the categories.

Note that this API is only available on `https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#VANILLA_ICE_CREAM` and above, so you will likely want to set `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#previewLayout` and `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#previewImage` as well to have the most coverage across versions.

See also `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#generatedPreviewCategories`, `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html#setWidgetPreview(android.content.ComponentName, int, android.widget.RemoteViews)`, `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html#getWidgetPreview(android.content.ComponentName, android.os.UserHandle, int)`, and `https://developer.android.com/reference/android/appwidget/AppWidgetManager.html#removeWidgetPreview(android.content.ComponentName, int)`.

```kotlin
import androidx.glance.appwidget.GlanceAppWidgetManager
import androidx.glance.appwidget.GlanceAppWidgetManager.Companion.SET_WIDGET_PREVIEWS_RESULT_RATE_LIMITED
import androidx.glance.appwidget.GlanceAppWidgetReceiver

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
    return
}
fun Class<GlanceAppWidgetReceiver>.hasPreviewForCategory(widgetCategory: Int): Boolean {
    val component = ComponentName(context, this)
    val providerInfo =
        (context.getSystemService(Context.APPWIDGET_SERVICE) as AppWidgetManager)
            .installedProviders
            .first { providerInfo -> providerInfo.provider == component }
    return providerInfo.generatedPreviewCategories.and(widgetCategory) != 0
}
val receiverClasses = listOf<Class<GlanceAppWidgetReceiver>>()
val glanceAppWidgetManager = GlanceAppWidgetManager(context)
withContext(Dispatchers.Default) {
    try {
        for (receiver in receiverClasses) {
            if (receiver.hasPreviewForCategory(WIDGET_CATEGORY_HOME_SCREEN)) {
                Log.i("Widget", "Skipped updating previews for $receiver")
                continue
            }
            if (
                glanceAppWidgetManager.setWidgetPreviews(receiver.kotlin) ==
                    SET_WIDGET_PREVIEWS_RESULT_RATE_LIMITED
            ) {
                Log.e("Widget", "Failed to set previews for $receiver, rate limited")
            }
        }
    } catch (e: Exception) {
        Log.e("Widget", "Error thrown when calling setWidgetPreview", e)
    }
}
```

| Parameters |
|---|---|
| `widgetCategories: https://developer.android.com/reference/kotlin/androidx/collection/IntSet = intSetOf( WIDGET_CATEGORY_HOME_SCREEN or WIDGET_CATEGORY_KEYGUARD or WIDGET_CATEGORY_SEARCHBOX )` | the widget categories for which to set previews. Each element of this set must be a combination of `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#WIDGET_CATEGORY_HOME_SCREEN`, `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#WIDGET_CATEGORY_KEYGUARD`, or `https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo.html#WIDGET_CATEGORY_SEARCHBOX`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetManager#SET_WIDGET_PREVIEWS_RESULT_SUCCESS()` if the preview was successfully updated. Returns `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetManager#SET_WIDGET_PREVIEWS_RESULT_RATE_LIMITED()` when the caller has hit a system-defined rate limit on setting previews for a particular provider. In this case, you may opt to schedule a task in the future to try again, if necessary. |

### GlanceAppWidget.updateAll

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/GlanceAppWidget.kt+function:updateAll) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/glance#1.0.0)

```
suspend fun GlanceAppWidget.updateAll(context: Context): Unit
```

Update all App Widgets managed by the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` class.

### GlanceAppWidget.updateIf

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/GlanceAppWidget.kt+function:updateIf)

```
suspend inline fun <State : Any?> GlanceAppWidget.updateIf(
    context: Context,
    predicate: (State) -> Boolean
): Unit
```

Update all App Widgets managed by the `https://developer.android.com/reference/kotlin/androidx/glance/appwidget/GlanceAppWidget` class, if they fulfill some condition.

## Top-level properties

### LocalAppWidgetOptions

Artifact: [androidx.glance:glance-appwidget](https://developer.android.com/jetpack/androidx/releases/glance) [View Source](https://cs.android.com/search?q=file:androidx/glance/appwidget/CompositionLocals.kt+symbol:LocalAppWidgetOptions) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/glance#1.0.0)

```
val LocalAppWidgetOptions: ProvidableCompositionLocal<Bundle>
```

Option Bundle accessible when generating an App Widget.

See AppWidgetManager#getAppWidgetOptions for details