위젯 검색 가능 여부

Android 8.0 (API 수준 26) 이상을 실행하는 기기에서 사용자는 고정된 바로가기도 만듭니다. 홈 화면에 위젯을 고정할 수 있습니다. 고정된 바로가기와 마찬가지로 고정된 위젯은 사용자에게 앱의 특정 작업에 대한 액세스 권한을 제공하며 추가할 수 있습니다.

반응형 레이아웃의 예
그림 2. 위젯 고정 예

사용자가 위젯을 고정하도록 허용

앱에서는 시스템이 위젯을 지원되는 런처를 추가하려면 다음 단계를 따르세요.

  1. 앱의 매니페스트 파일에서 위젯을 선언해야 합니다.

  2. 먼저 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)
}

자바

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);
}

사용자는 위젯 선택 도구를 통해 또는 앱에 전달될 수 있습니다. 자세한 내용은 검색 및 프로모션.