위젯 검색 가능 여부

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

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

사용자는 위젯 선택 도구를 통해 또는 위젯의 기능이 가장 관련이 있을 때 앱 내에서 위젯을 검색하고 추가합니다. 자세한 내용은 검색 및 프로모션을 참고하세요.