Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Em dispositivos com Android 8.0 (nível 26 da API) ou versões mais recentes, as telas de início que permitem
criar atalhos fixados também
permitem fixar widgets na tela inicial. Assim como os atalhos fixados, esses
widgets fixados oferecem aos usuários acesso a tarefas específicas no seu app e podem ser
adicionados à tela inicial diretamente do app, conforme mostrado no vídeo a seguir.
Figura 2. Exemplo de como fixar um widget.
Permitir que os usuários fixem um widget
No seu app, é possível criar uma solicitação para o sistema fixar um widget em uma tela de início compatível realizando as seguintes etapas:
Chame o método
requestPinAppWidget(), conforme mostrado no snippet de código a seguir:
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);}
Orientações de design relacionadas
Os usuários descobrem e adicionam seu widget pelo seletor de widgets ou no
app quando a funcionalidade do widget é mais relevante. Para mais informações, consulte
Descoberta e promoção.
O conteúdo e os exemplos de código nesta página estão sujeitos às licenças descritas na Licença de conteúdo. Java e OpenJDK são marcas registradas da Oracle e/ou suas afiliadas.
Última atualização 2025-08-21 UTC.
[null,null,["Última atualização 2025-08-21 UTC."],[],[],null,["# Widget discoverability\n\nOn devices running Android 8.0 (API level 26) and higher, launchers that let\nusers create [pinned shortcuts](/guide/topics/ui/shortcuts#shortcut-types) also\nlet them pin widgets onto their home screen. Similar to pinned shortcuts, these\n*pinned widgets* give users access to specific tasks in your app and can be\nadded to the home screen directly from the app, as shown in the following video.\n**Figure 2.**Example of pinning a widget.\n\nLet users pin a widget\n----------------------\n\nIn your app, you can create a request for the system to pin a widget onto a\nsupported launcher by completing the following steps:\n\n1. Make sure you [declare a widget in your app's manifest file](/guide/topics/appwidgets#Manifest).\n\n2. Call the\n [`requestPinAppWidget()`](/reference/android/appwidget/AppWidgetManager#requestPinAppWidget(android.content.ComponentName,%20android.os.Bundle,%20android.app.PendingIntent))\n method, as shown in the following code snippet:\n\n### Kotlin\n\n```kotlin\nval appWidgetManager = AppWidgetManager.getInstance(context)\nval myProvider = ComponentName(context, ExampleAppWidgetProvider::class.java)\n\nif (appWidgetManager.isRequestPinAppWidgetSupported()) {\n // Create the PendingIntent object only if your app needs to be notified\n // when the user chooses to pin the widget. Note that if the pinning\n // operation fails, your app isn't notified. This callback receives the ID\n // of the newly pinned widget (EXTRA_APPWIDGET_ID).\n val successCallback = PendingIntent.getBroadcast(\n /* context = */ context,\n /* requestCode = */ 0,\n /* intent = */ Intent(...),\n /* flags = */ PendingIntent.FLAG_UPDATE_CURRENT)\n\n appWidgetManager.requestPinAppWidget(myProvider, null, successCallback)\n}\n```\n\n### Java\n\n```java\nAppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);\nComponentName myProvider = new ComponentName(context, ExampleAppWidgetProvider.class);\n\nif (appWidgetManager.isRequestPinAppWidgetSupported()) {\n // Create the PendingIntent object only if your app needs to be notified\n // when the user chooses to pin the widget. Note that if the pinning\n // operation fails, your app isn't notified. This callback receives the ID\n // of the newly pinned widget (EXTRA_APPWIDGET_ID).\n PendingIntent successCallback = PendingIntent.getBroadcast(\n /* context = */ context,\n /* requestCode = */ 0,\n /* intent = */ new Intent(...),\n /* flags = */ PendingIntent.FLAG_UPDATE_CURRENT);\n\n appWidgetManager.requestPinAppWidget(myProvider, null, successCallback);\n}\n```\n| **Note:** If your app doesn't need to be notified of whether the system successfully pins a widget onto a supported launcher, you can pass in `null` as the third argument to `requestPinAppWidget()`.\n\nRelated design guidance\n-----------------------\n\nUsers discover and add your widget through the widget picker or from within your\napp when the widget's functionality is most relevant. For more information, see\n[Discovery and promotion](/design/ui/mobile/guides/widgets/discovery-promotion)."]]