앱에서 Glance 위젯 고정
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 8.0 (API 수준 26) 이상에서는 사용자가 앱 내에서 위젯을 홈 화면에 고정하도록 할 수 있습니다. 앱 내에서 직접 위젯을 홍보하는 것은 특히 사용자가 관련 작업을 완료한 후 또는 사용자가 앱의 기능에 반복적으로 액세스할 때 사용자 참여도를 높이는 좋은 방법입니다.
PIN 요청 만들기
위젯 고정을 시작하려면 GlanceAppWidgetManager
클래스의 requestPinGlanceAppWidget
메서드를 사용합니다. 더 낮은 버전의 Android에서 실행되는 앱의 경우 false를 반환합니다. 하지만 요청이 시스템에 전송되면 true를 반환합니다.
다음은 핀 요청을 만드는 방법의 예입니다.
@Composable
fun AnInAppComposable() {
val context = LocalContext.current
val coroutineScope = rememberCoroutineScope()
Button(
onClick = {
coroutineScope.launch {
GlanceAppWidgetManager(context).requestPinGlanceAppWidget(
receiver = MyWidgetReceiver::class.java,
preview = MyWidget(),
previewState = DpSize(245.dp, 115.dp)
)
}
}
) {}
}
이 예에서 MyWidgetReceiver
는 위젯의 콜백을 수신하는 클래스이고 MyWidget
은 고정하려는 Glance 위젯입니다. successCallback
은 위젯이 성공적으로 고정될 때 트리거되는 PendingIntent
입니다.
PIN 요청 응답 처리
사용자가 고정 요청 대화상자에 응답하면 앱이 응답을 수신합니다. 사용자가 요청을 수락하면 위젯이 홈 화면에 고정되고 successCallback
PendingIntent
이 트리거됩니다. 사용자가 요청을 거부하면 아무 일도 일어나지 않습니다.
successCallback
는 위젯이 홈 화면에 추가된 경우에만 트리거됩니다. 사용자가 요청을 거부하거나 런처가 고정을 지원하지 않는 경우에는 트리거되지 않습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-27(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-27(UTC)"],[],[],null,["With Android 8.0 (API level 26) and higher, you can let users pin your\nwidgets to their home screen within your app. Promoting widgets directly within\nyour app is a great way to increase user engagement, especially after a\nuser completes a related task, or when a user repeatedly accesses a feature in\nyour app.\n\nCreate a Pin Request\n\nTo initiate widget pinning, use the [`requestPinGlanceAppWidget`](/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetManager#requestPinGlanceAppWidget(java.lang.Class,androidx.glance.appwidget.GlanceAppWidget,kotlin.Any,android.app.PendingIntent)) method\nfrom the [`GlanceAppWidgetManager`](/reference/kotlin/androidx/glance/appwidget/GlanceAppWidgetManager) class. For apps running on lower versions\nof Android, this returns false. However if the request is successfully sent\nto the system, this returns true.\n\nHere is an example of how you can create a pin request:\n\n\n```kotlin\n@Composable\nfun AnInAppComposable() {\n val context = LocalContext.current\n val coroutineScope = rememberCoroutineScope()\n Button(\n onClick = {\n coroutineScope.launch {\n GlanceAppWidgetManager(context).requestPinGlanceAppWidget(\n receiver = MyWidgetReceiver::class.java,\n preview = MyWidget(),\n previewState = DpSize(245.dp, 115.dp)\n )\n }\n }\n ) {}\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/glance/GlancePinAppWidget.kt#L44-L59\n```\n\n\u003cbr /\u003e\n\nIn this example, `MyWidgetReceiver` is the class that receives the widget's\ncallbacks, and `MyWidget` is the Glance widget you want to pin. The\n`successCallback` is a `PendingIntent` that is triggered when the widget is\nsuccessfully pinned.\n\nHandle the Pin Request Response\n\nWhen a user responds to the pin request dialog, your app receives a\nresponse. If the user accepts the request, your widget is pinned to their\nhome screen, and the `successCallback` `PendingIntent` is triggered. If the\nuser denies the request, nothing happens.\n\nIt is important to note that the `successCallback` is only triggered if the\nwidget is successfully added to the home screen. It is not triggered if the user\ndenies the request or if the launcher does not support pinning."]]