Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf Geräten mit Android 8.0 (API-Level 26) und höher können Nutzer in Launchern, die das Erstellen von angepinnten Verknüpfungen ermöglichen, auch Widgets auf dem Startbildschirm anpinnen. Ähnlich wie bei angepinnten Verknüpfungen können Nutzer über angepinnte Widgets auf bestimmte Aufgaben in Ihrer App zugreifen. Sie können direkt über die App zum Startbildschirm hinzugefügt werden, wie im folgenden Video gezeigt.
Abbildung 2. Beispiel für das Anpinnen eines Widgets
Nutzern erlauben, ein Widget anzupinnen
In Ihrer App können Sie eine Anfrage erstellen, damit das System ein Widget an einen unterstützten Launcher anpinnt. Gehen Sie dazu so vor:
Rufen Sie die Methode requestPinAppWidget() auf, wie im folgenden Code-Snippet gezeigt:
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);}
Zugehörige Designanleitung
Nutzer können Ihr Widget über die Widget-Auswahl oder in Ihrer App hinzufügen, wenn die Funktion des Widgets am relevantesten ist. Weitere Informationen finden Sie unter Auffindbarkeit und Werbung.
Alle Inhalte und Codebeispiele auf dieser Seite unterliegen den Lizenzen wie im Abschnitt Inhaltslizenz beschrieben. Java und OpenJDK sind Marken oder eingetragene Marken von Oracle und/oder seinen Tochtergesellschaften.
Zuletzt aktualisiert: 2025-08-21 (UTC).
[null,null,["Zuletzt aktualisiert: 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)."]]