Added in API level 3

AppWidgetManager


open class AppWidgetManager
kotlin.Any
   ↳ android.appwidget.AppWidgetManager

Updates AppWidget state; gets information about installed AppWidget providers and other AppWidget related state.

.
Requires the PackageManager#FEATURE_APP_WIDGETS feature which can be detected using PackageManager.hasSystemFeature(String).

Summary

Constants
static String

Activity action to launch from your AppWidgetHost activity when you want to bind an AppWidget to display and bindAppWidgetIdIfAllowed returns false.

static String

Sent when it is time to configure your AppWidget while it is being added to a host.

static String

Sent when an instance of an AppWidget is deleted from its host.

static String

Sent when the last AppWidget of this provider is removed from the last host.

static String

Sent when an instance of an AppWidget is added to a host for the first time.

static String

Sent to widget hosts after AppWidget state related to the host has been restored from backup.

static String

Sent when the custom extras for an AppWidget change.

static String

Activity action to launch from your AppWidgetHost activity when you want to pick an AppWidget to display.

static String

Sent to an AppWidgetProvider after AppWidget state related to that provider has been restored from backup.

static String

Sent when it is time to update your AppWidget.

static String

An intent extra (int) that contains one appWidgetId.

static String

An intent extra that contains multiple appWidgetIds.

static String

An intent extra that contains multiple appWidgetIds.

static String

An intent extra which points to a bundle of extra information for a particular widget id.

static String

An extra that can be passed to requestPinAppWidget(ComponentName,Bundle,PendingIntent).

static String

An intent extra that contains the component name of a AppWidget provider.

static String

An intent extra that contains the user handle of the profile under which an AppWidget provider is registered.

static String

An intent extra to pass to the AppWidget picker containing a java.util.List of android.os.Bundle objects to mix in to the list of AppWidgets that are installed.

static String

An intent extra to pass to the AppWidget picker containing a java.util.List of AppWidgetProviderInfo objects to mix in to the list of AppWidgets that are installed.

static String

An intent extra attached to the ACTION_APPWIDGET_HOST_RESTORED broadcast, indicating the integer ID of the host whose widgets have just been restored.

static Int

A sentinel value that the AppWidget manager will never return as a appWidgetId.

static String

Field for the manifest meta-data tag.

static String

A bundle extra (int) that indicates which display the widget is currently being displayed on.

static String

A bundle extra that hints to the AppWidgetProvider the category of host that owns this this widget.

static String

A bundle extra (int) that contains the upper bound on the current width, in dips, of a widget instance.

static String

A bundle extra (int) that contains the upper bound on the current width, in dips, of a widget instance.

static String

A bundle extra (int) that contains the lower bound on the current height, in dips, of a widget instance.

static String

A bundle extra (int) that contains the lower bound on the current width, in dips, of a widget instance.

static String

A bundle extra (boolean) that contains whether or not an app has finished restoring a widget.

static String

A bundle extra (List<SizeF>) that contains the list of possible sizes, in dips, a widget instance can take.

Public methods
open Boolean
bindAppWidgetIdIfAllowed(appWidgetId: Int, provider: ComponentName!)

Set the component for a given appWidgetId.

open Boolean
bindAppWidgetIdIfAllowed(appWidgetId: Int, provider: ComponentName!, options: Bundle!)

Set the component for a given appWidgetId.

open Boolean
bindAppWidgetIdIfAllowed(appWidgetId: Int, user: UserHandle!, provider: ComponentName!, options: Bundle!)

Set the provider for a given appWidgetId if the caller has a permission.

open IntArray!

Get the list of appWidgetIds that have been bound to the given AppWidget provider.

open AppWidgetProviderInfo!
getAppWidgetInfo(appWidgetId: Int)

Returns the AppWidgetProviderInfo for the specified AppWidget.

open Bundle!
getAppWidgetOptions(appWidgetId: Int)

Get the extras associated with a given widget instance.

open MutableList<AppWidgetProviderInfo!>!

Return a list of the AppWidget providers that are currently installed.

open MutableList<AppWidgetProviderInfo!>

Gets the AppWidget providers for the given package and user profile.

open MutableList<AppWidgetProviderInfo!>

Gets the AppWidget providers for the given user profile.

open static AppWidgetManager!
getInstance(context: Context!)

Get the AppWidgetManager instance to use for the supplied Context object.

open RemoteViews?
getWidgetPreview(provider: ComponentName, profile: UserHandle?, widgetCategory: Int)

Get the RemoteViews previews for this widget.

open Boolean

Return TRUE if the default launcher supports requestPinAppWidget(ComponentName,Bundle,PendingIntent)

open Unit
notifyAppWidgetViewDataChanged(appWidgetId: Int, viewId: Int)

Notifies the specified collection view in the specified AppWidget instance to invalidate its data.

open Unit
notifyAppWidgetViewDataChanged(appWidgetIds: IntArray!, viewId: Int)

Notifies the specified collection view in all the specified AppWidget instances to invalidate their data.

open Unit
partiallyUpdateAppWidget(appWidgetId: Int, views: RemoteViews!)

Perform an incremental update or command on the widget specified by appWidgetId.

open Unit
partiallyUpdateAppWidget(appWidgetIds: IntArray!, views: RemoteViews!)

Perform an incremental update or command on the widget(s) specified by appWidgetIds.

open MutableList<AppWidgetEvent!>
queryAppWidgetEvents(beginTime: Long, endTime: Long)

Query for app widget interaction events in the given time range.

open Unit
removeWidgetPreview(provider: ComponentName, widgetCategories: Int)

Remove this provider's preview for the specified widget categories.

open Boolean
requestPinAppWidget(provider: ComponentName, extras: Bundle?, successCallback: PendingIntent?)

Request to pin an app widget on the current launcher.

open Boolean
setWidgetPreview(provider: ComponentName, widgetCategories: Int, preview: RemoteViews)

Set a preview for this widget.

open Unit

Set the RemoteViews to use for all AppWidget instances for the supplied AppWidget provider.

open Unit
updateAppWidget(appWidgetId: Int, views: RemoteViews!)

Set the RemoteViews to use for the specified appWidgetId.

open Unit
updateAppWidget(appWidgetIds: IntArray!, views: RemoteViews!)

Set the RemoteViews to use for the specified appWidgetIds.

open Unit
updateAppWidgetOptions(appWidgetId: Int, options: Bundle!)

Update the extras for a given widget instance.

open Unit
updateAppWidgetProviderInfo(provider: ComponentName!, metaDataKey: String?)

Updates the info for the supplied AppWidget provider.

Constants

ACTION_APPWIDGET_BIND

Added in API level 16
static val ACTION_APPWIDGET_BIND: String

Activity action to launch from your AppWidgetHost activity when you want to bind an AppWidget to display and bindAppWidgetIdIfAllowed returns false.

You must supply the following extras:

EXTRA_APPWIDGET_ID A newly allocated appWidgetId, which will be bound to the AppWidget provider you provide.
EXTRA_APPWIDGET_PROVIDER The BroadcastReceiver that will be the AppWidget provider for this AppWidget.
EXTRA_APPWIDGET_PROVIDER_PROFILE An optional handle to a user profile under which runs the provider for this AppWidget.

The system will respond with an onActivityResult call with the following extras in the intent:

EXTRA_APPWIDGET_ID The appWidgetId that you supplied in the original intent.

When you receive the result from the AppWidget bind activity, if the resultCode is android.app.Activity#RESULT_OK, the AppWidget has been bound. You should then check the AppWidgetProviderInfo for the returned AppWidget, and if it has one, launch its configuration activity. If android.app.Activity#RESULT_CANCELED is returned, you should delete the appWidgetId.

Value: "android.appwidget.action.APPWIDGET_BIND"

ACTION_APPWIDGET_CONFIGURE

Added in API level 3
static val ACTION_APPWIDGET_CONFIGURE: String

Sent when it is time to configure your AppWidget while it is being added to a host. This action is not sent as a broadcast to the AppWidget provider, but as a startActivity to the activity specified in the AppWidgetProviderInfo.

The intent will contain the following extras:

EXTRA_APPWIDGET_ID The appWidgetId to configure.

If you return android.app.Activity#RESULT_OK using android.app.Activity#setResult, the AppWidget will be added, and you will receive an ACTION_APPWIDGET_UPDATE broadcast for this AppWidget. If you return android.app.Activity#RESULT_CANCELED, the host will cancel the add and not display this AppWidget, and you will receive a ACTION_APPWIDGET_DELETED broadcast.

Value: "android.appwidget.action.APPWIDGET_CONFIGURE"

ACTION_APPWIDGET_DELETED

Added in API level 3
static val ACTION_APPWIDGET_DELETED: String

Sent when an instance of an AppWidget is deleted from its host.

This is a protected intent that can only be sent by the system.

Value: "android.appwidget.action.APPWIDGET_DELETED"

ACTION_APPWIDGET_DISABLED

Added in API level 3
static val ACTION_APPWIDGET_DISABLED: String

Sent when the last AppWidget of this provider is removed from the last host.

This is a protected intent that can only be sent by the system.

Value: "android.appwidget.action.APPWIDGET_DISABLED"

ACTION_APPWIDGET_ENABLED

Added in API level 3
static val ACTION_APPWIDGET_ENABLED: String

Sent when an instance of an AppWidget is added to a host for the first time. This broadcast is sent at boot time if there is a AppWidgetHost installed with an instance for this provider.

This is a protected intent that can only be sent by the system.

Value: "android.appwidget.action.APPWIDGET_ENABLED"

ACTION_APPWIDGET_HOST_RESTORED

Added in API level 21
static val ACTION_APPWIDGET_HOST_RESTORED: String

Sent to widget hosts after AppWidget state related to the host has been restored from backup. The intent contains information about how to translate AppWidget ids from the restored data to their new equivalents. If an application maintains multiple separate widget host instances, it will receive this broadcast separately for each one.

The intent will contain the following extras:

EXTRA_APPWIDGET_OLD_IDS The set of appWidgetIds represented in a restored backup that have been successfully incorporated into the current environment. This may be all of the AppWidgets known to this application, or just a subset. Each entry in this array of appWidgetIds has a corresponding entry in the EXTRA_APPWIDGET_IDS extra.
EXTRA_APPWIDGET_IDS The set of appWidgetIds now valid for this application. The app should look at its restored widget configuration and translate each appWidgetId in the EXTRA_APPWIDGET_OLD_IDS array to its new value found at the corresponding index within this array.
EXTRA_HOST_ID The integer ID of the widget host instance whose state has just been restored.

This is a protected intent that can only be sent by the system.

Value: "android.appwidget.action.APPWIDGET_HOST_RESTORED"

ACTION_APPWIDGET_OPTIONS_CHANGED

Added in API level 16
static val ACTION_APPWIDGET_OPTIONS_CHANGED: String

Sent when the custom extras for an AppWidget change.

This is a protected intent that can only be sent by the system.

Value: "android.appwidget.action.APPWIDGET_UPDATE_OPTIONS"

ACTION_APPWIDGET_PICK

Added in API level 3
static val ACTION_APPWIDGET_PICK: String

Activity action to launch from your AppWidgetHost activity when you want to pick an AppWidget to display. The AppWidget picker activity will be launched.

You must supply the following extras:

EXTRA_APPWIDGET_ID A newly allocated appWidgetId, which will be bound to the AppWidget provider once the user has selected one.

The system will respond with an onActivityResult call with the following extras in the intent:

EXTRA_APPWIDGET_ID The appWidgetId that you supplied in the original intent.

When you receive the result from the AppWidget pick activity, if the resultCode is android.app.Activity#RESULT_OK, an AppWidget has been selected. You should then check the AppWidgetProviderInfo for the returned AppWidget, and if it has one, launch its configuration activity. If android.app.Activity#RESULT_CANCELED is returned, you should delete the appWidgetId.

Value: "android.appwidget.action.APPWIDGET_PICK"

ACTION_APPWIDGET_RESTORED

Added in API level 21
static val ACTION_APPWIDGET_RESTORED: String

Sent to an AppWidgetProvider after AppWidget state related to that provider has been restored from backup. The intent contains information about how to translate AppWidget ids from the restored data to their new equivalents.

The intent will contain the following extras:

EXTRA_APPWIDGET_OLD_IDS The set of appWidgetIds represented in a restored backup that have been successfully incorporated into the current environment. This may be all of the AppWidgets known to this application, or just a subset. Each entry in this array of appWidgetIds has a corresponding entry in the EXTRA_APPWIDGET_IDS extra.
EXTRA_APPWIDGET_IDS The set of appWidgetIds now valid for this application. The app should look at its restored widget configuration and translate each appWidgetId in the EXTRA_APPWIDGET_OLD_IDS array to its new value found at the corresponding index within this array.

This is a protected intent that can only be sent by the system.

Value: "android.appwidget.action.APPWIDGET_RESTORED"

ACTION_APPWIDGET_UPDATE

Added in API level 3
static val ACTION_APPWIDGET_UPDATE: String

Sent when it is time to update your AppWidget.

This may be sent in response to a new instance for this AppWidget provider having been instantiated, the requested update interval having lapsed, or the system booting.

The intent will contain the following extras:

EXTRA_APPWIDGET_IDS The appWidgetIds to update. This may be all of the AppWidgets created for this provider, or just a subset. The system tries to send updates for as few AppWidget instances as possible.
Value: "android.appwidget.action.APPWIDGET_UPDATE"

EXTRA_APPWIDGET_ID

Added in API level 3
static val EXTRA_APPWIDGET_ID: String

An intent extra (int) that contains one appWidgetId.

The value will be an int that can be retrieved like this:

Value: "appWidgetId"

EXTRA_APPWIDGET_IDS

Added in API level 3
static val EXTRA_APPWIDGET_IDS: String

An intent extra that contains multiple appWidgetIds.

The value will be an int array that can be retrieved like this:

Value: "appWidgetIds"

EXTRA_APPWIDGET_OLD_IDS

Added in API level 21
static val EXTRA_APPWIDGET_OLD_IDS: String

An intent extra that contains multiple appWidgetIds. These are id values as they were provided to the application during a recent restore from backup. It is attached to the ACTION_APPWIDGET_RESTORED broadcast intent.

The value will be an int array that can be retrieved like this:

Value: "appWidgetOldIds"

EXTRA_APPWIDGET_OPTIONS

Added in API level 16
static val EXTRA_APPWIDGET_OPTIONS: String

An intent extra which points to a bundle of extra information for a particular widget id. In particular this bundle can contain OPTION_APPWIDGET_MIN_WIDTH, OPTION_APPWIDGET_MIN_HEIGHT, OPTION_APPWIDGET_MAX_WIDTH, OPTION_APPWIDGET_MAX_HEIGHT.

Value: "appWidgetOptions"

EXTRA_APPWIDGET_PREVIEW

Added in API level 26
static val EXTRA_APPWIDGET_PREVIEW: String

An extra that can be passed to requestPinAppWidget(ComponentName,Bundle,PendingIntent). This would allow the launcher app to present a custom preview to the user.

The value should be a RemoteViews similar to what is used with #updateAppWidget calls.

Value: "appWidgetPreview"

EXTRA_APPWIDGET_PROVIDER

Added in API level 16
static val EXTRA_APPWIDGET_PROVIDER: String

An intent extra that contains the component name of a AppWidget provider.

The value will be an android.content.ComponentName.

Value: "appWidgetProvider"

EXTRA_APPWIDGET_PROVIDER_PROFILE

Added in API level 21
static val EXTRA_APPWIDGET_PROVIDER_PROFILE: String

An intent extra that contains the user handle of the profile under which an AppWidget provider is registered.

The value will be a android.os.UserHandle.

Value: "appWidgetProviderProfile"

EXTRA_CUSTOM_EXTRAS

Added in API level 3
static val EXTRA_CUSTOM_EXTRAS: String

An intent extra to pass to the AppWidget picker containing a java.util.List of android.os.Bundle objects to mix in to the list of AppWidgets that are installed. It will be added to the extras object on the android.content.Intent that is returned from the picker activity. {@more}

Value: "customExtras"

EXTRA_CUSTOM_INFO

Added in API level 3
static val EXTRA_CUSTOM_INFO: String

An intent extra to pass to the AppWidget picker containing a java.util.List of AppWidgetProviderInfo objects to mix in to the list of AppWidgets that are installed. (This is how the launcher shows the search widget).

Value: "customInfo"