androidx.glance.appwidget.action

Interfaces

ActionCallback

A callback executed in response to the user action, before the content is updated.

Top-level functions summary

inline Action

Creates an Action that executes a given ActionCallback implementation

Action
<T : ActionCallback> actionRunCallback(
    callbackClass: Class<T>,
    parameters: ActionParameters
)

Creates an Action that executes a given ActionCallback implementation

inline Action

Creates an Action that launches the specified BroadcastReceiver when triggered.

Action

Creates an Action that launches the BroadcastReceiver specified by the given ComponentName.

Action

Creates an Action that launches a BroadcastReceiver from the given Intent when triggered.

Action

Creates an Action that launches the specified BroadcastReceiver when triggered.

Action
actionSendBroadcast(action: String, componentName: ComponentName?)

Creates an Action that launches the BroadcastReceiver specified by the given action.

Action

Creates an Action that launches an Activity from the given Intent when triggered.

Action
@ExperimentalGlanceApi
actionStartActivity(
    intent: Intent,
    parameters: ActionParameters,
    activityOptions: Bundle?
)

Creates an Action that launches an Activity from the given Intent when triggered.

inline Action
<T : Service> actionStartService(isForegroundService: Boolean)

Creates an Action that launches the specified Service when triggered.

Action
actionStartService(
    componentName: ComponentName,
    isForegroundService: Boolean
)

Creates an Action that launches the Service specified by the given ComponentName.

Action
actionStartService(intent: Intent, isForegroundService: Boolean)

Creates an Action that launches a Service from the given Intent when triggered.

Action
<T : Service> actionStartService(
    service: Class<T>,
    isForegroundService: Boolean
)

Creates an Action that launches the specified Service when triggered.

Top-level properties summary

ActionParameters.Key<Boolean>

This key is used to access the current checked value for actions that are triggered by compound button interactions (e.g.

Top-level functions

actionRunCallback

inline fun <T : ActionCallback> actionRunCallback(
    parameters: ActionParameters = actionParametersOf()
): Action

Creates an Action that executes a given ActionCallback implementation

Parameters
parameters: ActionParameters = actionParametersOf()

the parameters associated with the action

actionRunCallback

fun <T : ActionCallback> actionRunCallback(
    callbackClass: Class<T>,
    parameters: ActionParameters = actionParametersOf()
): Action

Creates an Action that executes a given ActionCallback implementation

Parameters
callbackClass: Class<T>

the class that implements ActionCallback

parameters: ActionParameters = actionParametersOf()

the parameters associated with the action

actionSendBroadcast

inline fun <T : BroadcastReceiver> actionSendBroadcast(): Action

Creates an Action that launches the specified BroadcastReceiver when triggered.

actionSendBroadcast

fun actionSendBroadcast(componentName: ComponentName): Action

Creates an Action that launches the BroadcastReceiver specified by the given ComponentName.

Parameters
componentName: ComponentName

component of the BroadcastReceiver to launch

actionSendBroadcast

fun actionSendBroadcast(intent: Intent): Action

Creates an Action that launches a BroadcastReceiver from the given Intent when triggered. The intent should specify a component with Intent.setClass or Intent.setComponent.

Parameters
intent: Intent

the Intent used to launch the BroadcastReceiver

actionSendBroadcast

fun <T : BroadcastReceiver> actionSendBroadcast(receiver: Class<T>): Action

Creates an Action that launches the specified BroadcastReceiver when triggered.

Parameters
receiver: Class<T>

class of the BroadcastReceiver to launch

actionSendBroadcast

fun actionSendBroadcast(action: String, componentName: ComponentName? = null): Action

Creates an Action that launches the BroadcastReceiver specified by the given action.

Parameters
action: String

of the BroadcastReceiver to launch

componentName: ComponentName? = null

optional ComponentName of the target BroadcastReceiver

actionStartActivity

fun actionStartActivity(
    intent: Intent,
    parameters: ActionParameters = actionParametersOf()
): Action

Creates an Action that launches an Activity from the given Intent when triggered. The intent should specify a component with Intent.setClass or Intent.setComponent.

This action is supported by app widgets only.

The given intent will be wrapped in a android.app.PendingIntent. This means that if you create multiple actions with this function, they will be conflated unless the underlying intents are distinct from one another, as defined by Intent.filterEquals. For example, if you create two Intents that target the same Activity but only differ by parameters, they will get conflated (the PendingIntent created by the first call to actionStartActivity will be overwritten by the second). A simple way to avoid this is to set a unique data URI on these intents, so that they are distinct as defined by Intent.filterEquals. There is more information in the class documentation for android.app.PendingIntent. If you do not set one, the library will add a unique URI on the intent you provide here.

Parameters
intent: Intent

the intent used to launch the activity

parameters: ActionParameters = actionParametersOf()

the parameters associated with the action. Parameter values will be added to the activity intent, keyed by the parameter key name string.

actionStartActivity

@ExperimentalGlanceApi
fun actionStartActivity(
    intent: Intent,
    parameters: ActionParameters = actionParametersOf(),
    activityOptions: Bundle? = null
): Action

Creates an Action that launches an Activity from the given Intent when triggered. The intent should specify a component with Intent.setClass or Intent.setComponent.

This action is supported by app widgets only.

The given intent will be wrapped in a android.app.PendingIntent. This means that if you create multiple actions with this function, they will be conflated unless the underlying intents are distinct from one another, as defined by Intent.filterEquals. For example, if you create two Intents that target the same Activity but only differ by parameters, they will get conflated (the PendingIntent created by the first call to actionStartActivity will be overwritten by the second). A simple way to avoid this is to set a unique data URI on these intents, so that they are distinct as defined by Intent.filterEquals. There is more information in the class documentation for android.app.PendingIntent. If you do not set one, the library will add a unique URI on the intent you provide here.

Parameters
intent: Intent

the intent used to launch the activity

parameters: ActionParameters = actionParametersOf()

the parameters associated with the action. Parameter values will be added to the activity intent, keyed by the parameter key name string.

activityOptions: Bundle? = null

Additional options built from an android.app.ActivityOptions to apply to an activity start.

actionStartService

inline fun <T : Service> actionStartService(isForegroundService: Boolean = false): Action

Creates an Action that launches the specified Service when triggered.

Parameters
isForegroundService: Boolean = false

set to true when the provided Service runs in foreground. This flag is only used for device versions after android.os.Build.VERSION_CODES.O that requires foreground service to be launched differently.

actionStartService

fun actionStartService(
    componentName: ComponentName,
    isForegroundService: Boolean = false
): Action

Creates an Action that launches the Service specified by the given ComponentName.

Parameters
componentName: ComponentName

component of the Service to launch

isForegroundService: Boolean = false

set to true when the provided Service runs in foreground. This flag is only used for device versions after android.os.Build.VERSION_CODES.O that requires foreground service to be launched differently

actionStartService

fun actionStartService(intent: Intent, isForegroundService: Boolean = false): Action

Creates an Action that launches a Service from the given Intent when triggered. The intent should specify a component with Intent.setClass or Intent.setComponent.

Parameters
intent: Intent

the intent used to launch the activity

isForegroundService: Boolean = false

set to true when the provided Service runs in foreground. This flag is only used for device versions after android.os.Build.VERSION_CODES.O that requires foreground service to be launched differently

actionStartService

fun <T : Service> actionStartService(
    service: Class<T>,
    isForegroundService: Boolean = false
): Action

Creates an Action that launches the specified Service when triggered.

Parameters
service: Class<T>

class of the Service to launch

isForegroundService: Boolean = false

set to true when the provided Service runs in foreground. This flag is only used for device versions after android.os.Build.VERSION_CODES.O that requires foreground service to be launched differently

Top-level properties

ToggleableStateKey

val ToggleableStateKeyActionParameters.Key<Boolean>

This key is used to access the current checked value for actions that are triggered by compound button interactions (e.g. CheckBox, Switch). This key is used to retrieve the value from the ActionParameters passed to the action.