Bir Bakışta widget'larını uygulama içinde sabitleme
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Android 8.0 (API düzeyi 26) ve sonraki sürümlerde, kullanıcıların widget'larınızı uygulamanızdan ana ekranlarına sabitlemesine izin verebilirsiniz. Widget'ları doğrudan uygulamanızda tanıtmak, özellikle kullanıcı ilgili bir görevi tamamladıktan sonra veya uygulamanızdaki bir özelliğe tekrar tekrar eriştiğinde kullanıcı etkileşimini artırmanın harika bir yoludur.
PIN isteği oluşturma
Widget'ı sabitleme işlemini başlatmak için requestPinGlanceAppWidget
sınıfındaki GlanceAppWidgetManager
yöntemini kullanın. Android'in daha eski sürümlerinde çalışan uygulamalar için bu işlev false değerini döndürür. Ancak istek sisteme başarıyla gönderilirse bu işlev true değerini döndürür.
PIN isteğini nasıl oluşturabileceğinize dair bir örneği aşağıda bulabilirsiniz:
@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)
)
}
}
) {}
}
Bu örnekte MyWidgetReceiver
, widget'ın geri çağırmalarını alan sınıf, MyWidget
ise sabitlemek istediğiniz Glance widget'ıdır. successCallback
, widget başarıyla sabitlendiğinde tetiklenen bir PendingIntent
'dir.
Pin İsteği Yanıtını İşleme
Kullanıcı pin isteği iletişim kutusunu yanıtladığında uygulamanız bir yanıt alır. Kullanıcı isteği kabul ederse widget'ınız ana ekranına sabitlenir ve successCallback
PendingIntent
tetiklenir. Kullanıcı isteği reddederse hiçbir şey olmaz.
successCallback
işlevinin yalnızca widget ana ekrana başarıyla eklendiğinde tetiklendiğini unutmayın. Kullanıcı isteği reddederse veya başlatıcı sabitlemeyi desteklemiyorsa tetiklenmez.
Bu sayfadaki içerik ve kod örnekleri, İçerik Lisansı sayfasında açıklanan lisanslara tabidir. Java ve OpenJDK, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-26 UTC.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 2025-08-26 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/5673ffc60b614daf028ee936227128eb8c4f9781/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."]]