Widget discoverability

On devices running Android 8.0 (API level 26) and higher, launchers that let users create pinned shortcuts also let them pin widgets onto their home screen. Similar to pinned shortcuts, these pinned widgets give users access to specific tasks in your app and can be added to the home screen directly from the app, as shown in the following video.

Example of responsive layout
Figure 2. Example of pinning a widget.

Let users pin a widget

In your app, you can create a request for the system to pin a widget onto a supported launcher by completing the following steps:

  1. Make sure you declare a widget in your app’s manifest file.

  2. Call the requestPinAppWidget() method, as shown in the following code snippet:

Kotlin

valappWidgetManager=AppWidgetManager.getInstance(context)
valmyProvider=ComponentName(context,ExampleAppWidgetProvider::class.java)
if(appWidgetManager.isRequestPinAppWidgetSupported()){
// Create the PendingIntent object only if your app needs to be notified
// when the user chooses to pin the widget. Note that if the pinning
// operation fails, your app isn't notified. This callback receives the ID
// of the newly pinned widget (EXTRA_APPWIDGET_ID).
valsuccessCallback=PendingIntent.getBroadcast(
/* context = */context,
/* requestCode = */0,
/* intent = */Intent(...),
/* flags = */PendingIntent.FLAG_UPDATE_CURRENT)
appWidgetManager.requestPinAppWidget(myProvider,null,successCallback)
}

Java

AppWidgetManagerappWidgetManager=AppWidgetManager.getInstance(context);
ComponentNamemyProvider=newComponentName(context,ExampleAppWidgetProvider.class);
if(appWidgetManager.isRequestPinAppWidgetSupported()){
// Create the PendingIntent object only if your app needs to be notified
// when the user chooses to pin the widget. Note that if the pinning
// operation fails, your app isn't notified. This callback receives the ID
// of the newly pinned widget (EXTRA_APPWIDGET_ID).
PendingIntentsuccessCallback=PendingIntent.getBroadcast(
/* context = */context,
/* requestCode = */0,
/* intent = */newIntent(...),
/* flags = */PendingIntent.FLAG_UPDATE_CURRENT);
appWidgetManager.requestPinAppWidget(myProvider,null,successCallback);
}

Users discover and add your widget through the widget picker or from within your app when the widget's functionality is most relevant. For more information, see Discovery and promotion.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025年12月17日 UTC.