Android 8.0 (API 수준 26) 이상을 실행하는 기기에서 사용자가 고정된 바로가기를 만들 수 있는 런처를 사용하여 위젯을 홈 화면에 고정할 수도 있습니다. 고정된 바로가기와 마찬가지로 고정된 위젯을 사용하면 앱의 특정 작업에 액세스할 수 있으며 다음 동영상에 표시된 것처럼 앱에서 직접 홈 화면에 추가할 수 있습니다.
그림 2. 위젯을 고정하는 예
사용자가 위젯을 고정하도록 허용
앱에서 다음 단계를 완료하여 지원되는 런처에 위젯을 고정하도록 시스템에 요청할 수 있습니다.
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)}
자바
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);}
관련 설계 안내
사용자는 위젯 선택기를 통해 또는 위젯의 기능이 가장 관련성이 있을 때 앱 내에서 위젯을 검색하고 추가합니다. 자세한 내용은 검색 및 프로모션을 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-21(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 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)."]]