במכשירים שמותקנת בהם גרסת Android 8.0 (API ברמה 26) ומעלה, אפליקציות להפעלת אפליקציות שמאפשרות למשתמשים ליצור קיצורי דרך מוצמדים מאפשרות להם גם להצמיד ווידג'טים למסך הבית. בדומה לקיצורי דרך מוצמדים, ווידג'טים מוצמדים מאפשרים למשתמשים לגשת למשימות ספציפיות באפליקציה שלכם, ואפשר להוסיף אותם למסך הבית ישירות מהאפליקציה, כמו שמוצג בסרטון הבא.

המשתמשים יכולים להצמיד ווידג'ט
כדי ליצור באפליקציה בקשה למערכת להצמיד ווידג'ט למרכז אפליקציות נתמך, פועלים לפי השלבים הבאים:
מבצעים קריאה לשיטה
requestPinAppWidget()
, כמו שמוצג בקטע הקוד הבא:
Kotlin
val appWidgetManager = AppWidgetManager.getInstance(context) val myProvider = 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). val successCallback = PendingIntent.getBroadcast( /* context = */ context, /* requestCode = */ 0, /* intent = */ Intent(...), /* flags = */ PendingIntent.FLAG_UPDATE_CURRENT) appWidgetManager.requestPinAppWidget(myProvider, null, successCallback) }
Java
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); ComponentName myProvider = new ComponentName(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). PendingIntent successCallback = PendingIntent.getBroadcast( /* context = */ context, /* requestCode = */ 0, /* intent = */ new Intent(...), /* flags = */ PendingIntent.FLAG_UPDATE_CURRENT); appWidgetManager.requestPinAppWidget(myProvider, null, successCallback); }
הנחיות עיצוב קשורות
המשתמשים יכולים לגלות את הווידג'ט ולהוסיף אותו דרך כלי בחירת הווידג'טים או מתוך האפליקציה שלכם, כשהפונקציונליות של הווידג'ט הכי רלוונטית. מידע נוסף זמין במאמר בנושא גילוי וקידום.