바로가기 만들기

바로가기는 사용자가 특정 유형의 콘텐츠를 쉽게 찾을 수 있도록 빠르게 액세스할 수 있습니다.

앱 바로가기와 고정된 바로가기의 대비를 보여주는 이미지
그림 1. 앱 바로가기 및 고정된 바로가기

바로가기로 콘텐츠를 전송하는 방법은 사용 사례와 바로가기의 컨텍스트가 앱 기반인지 사용자 주도인지인지 확인합니다. 비록 정적인 바로가기의 컨텍스트는 변경되지 않고 동적 바로가기의 컨텍스트는 끊임없이 앱이 두 경우 모두 컨텍스트를 주도합니다. 사용자가 앱이 콘텐츠를 제공하는 방법(예: 고정된 바로가기, 컨텍스트는 사용자가 정의합니다 다음 시나리오에서는 애플리케이션의 몇 가지 용도를 각 단축키 유형에 대한 케이스:

  • 정적 단축키 는 일관된 단축키를 사용하여 콘텐츠에 연결되는 앱에 가장 적합합니다. 사용자와 상호작용하는 전체 기간 동안 . 대부분의 런처는 4개 디스플레이만 바로가기를 모두 사용하는 대신 정적 바로가기는 루틴을 실행하는 데 유용합니다. 작업을 일관성있게 처리(예: 사용자가 캘린더 보기 또는 이메일을 사용하는 것이 좋습니다 .
  • 동적 단축키는 제공합니다. 컨텍스트 인식 바로가기는 사용자가 앱에서 수행하는 액션 예를 들어 사용자가 다른 사용자와 시작할 때 현재 레벨에서 시작하는 경우 단축키를 자주 사용합니다. 동적 바로가기를 사용하면 바로가기를 업데이트할 수 있습니다. 사용자가 레벨을 통과할 때마다
  • 고정됨 단축키는 특정 사용자 주도 작업에 사용됩니다. 예를 들어 사용자가 특정 웹사이트를 런처에 고정하려고 할 수 있습니다. 이것은 맞춤 작업을 할 수 있기 때문에 유용합니다. 기본 검색엔진을 사용하는 것보다 한 단계로 웹사이트 탐색 가상 머신 인스턴스입니다

정적 바로가기 만들기

정적 바로가기는 앱 내의 일반 작업 링크를 제공합니다. 작업은 앱의 현재 버전이 제공되는 기간 동안 일관되게 유지되어야 합니다. 정적 바로가기에 좋은 옵션으로는 보낸 메시지 보기, 알람이 울리고, 일일 사용자의 운동 활동이 표시됩니다.

정적 바로가기를 만들려면 다음 단계를 따르세요.

  1. 앱의 AndroidManifest.xml 파일에서 인텐트 필터는 android.intent.action.MAIN 액션과 <ph type="x-smartling-placeholder">android.intent.category.LAUNCHER</ph> 카테고리입니다.

  2. 여기에 <meta-data> 요소를 이 액티비티에 추가합니다. 다음과 같이 정의됩니다.

      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                package="com.example.myapplication">
        <application ... >
          <activity android:name="Main">
            <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            
            <meta-data android:name="android.app.shortcuts"
                       android:resource="@xml/shortcuts" /> 
          </activity>
        </application>
      </manifest>
      
    드림 <ph type="x-smartling-placeholder">
  3. res/xml/shortcuts.xml라는 새 리소스 파일을 만듭니다.

  4. 새 리소스 파일에서 <shortcuts> 루트 요소를 추가합니다. 이 클래스는 <shortcut> 요소 목록을 포함합니다. 각 <shortcut> 요소: 정적 요소에 관한 정보 포함 바로 가기(아이콘, 설명 라벨, 실행 인텐트 등) 앱 내에서:

      <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
        <shortcut
          android:shortcutId="compose"
          android:enabled="true"
          android:icon="@drawable/compose_icon"
          android:shortcutShortLabel="@string/compose_shortcut_short_label1"
          android:shortcutLongLabel="@string/compose_shortcut_long_label1"
          android:shortcutDisabledMessage="@string/compose_disabled_message1">
          <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.example.myapplication"
            android:targetClass="com.example.myapplication.ComposeActivity" />
          <!-- If your shortcut is associated with multiple intents, include them
               here. The last intent in the list determines what the user sees when
               they launch this shortcut. -->
          <categories android:name="android.shortcut.conversation" />
          <capability-binding android:key="actions.intent.CREATE_MESSAGE" />
        </shortcut>
        <!-- Specify more shortcuts here. -->
      </shortcuts>
      

속성 값 맞춤설정

다음 목록에는 정적 바로가기입니다 android:shortcutIdandroid:shortcutShortLabel입니다. 다른 모든 값은 선택사항입니다.

android:shortcutId

단축키를 나타내는 문자열 리터럴입니다. ShortcutManager 객체는 해당 객체에 대해 작업을 수행합니다.

<ph type="x-smartling-placeholder">
android:shortcutShortLabel

바로가기의 목적을 설명하는 간결한 구문입니다. 가능하면 이 간단한 설명은 10자(영문 기준)로 제한하세요.

자세한 내용은 setShortLabel()를 참고하세요.

<ph type="x-smartling-placeholder">
android:shortcutLongLabel

바로가기의 목적을 설명하는 확장된 구문입니다. 데이터가 충분한 경우 100, 000픽셀을 반환하므로 런처는 android:shortcutShortLabel 가능하면 이 분량을 최대 12자(영문 25자)까지 입력할 수 있습니다.

자세한 내용은 setLongLabel()를 참고하세요.

<ph type="x-smartling-placeholder">
android:shortcutDisabledMessage

사용자가 실행하려고 할 때 지원되는 런처에 표시되는 메시지입니다. 사용 중지된 단축키를 실행합니다. 메시지는 사용자에게 단축키가 사용 중지되었습니다. 이 속성 값은 다음과 같은 경우 아무런 영향을 미치지 않습니다. android:enabledtrue입니다.

<ph type="x-smartling-placeholder">
android:enabled

사용자가 지원되는 있습니다. android:enabled의 기본값은 다음과 같습니다. true입니다. false로 설정하면 그 이유를 설명하는 android:shortcutDisabledMessage 단축키를 사용 중지합니다. 이러한 메시지를 제공할 필요가 없다고 생각되면 XML 파일에서 바로가기를 완전히 삭제합니다.

android:icon

비트맵 또는 적응형 아이콘입니다. 이 값은 이미지 가능하면 적응형 아이콘을 사용하여 성능과 일관성

<ph type="x-smartling-placeholder">

내부 요소 구성

앱의 정적 바로가기를 나열하는 XML 파일은 다음을 지원합니다. 각 <shortcut> 요소 내부의 요소. 나 반드시 각 항목의 intent 내부 요소를 포함해야 합니다. 정적 바로가기를 생성합니다.

intent

사용자가 바로가기를 선택할 때 시스템에서 실행하는 작업입니다. 이 인텐트는 android:action 값을 제공해야 합니다. 속성의 값을 제공합니다.

<ph type="x-smartling-placeholder">

단일 바로가기에 여러 인텐트를 제공할 수 있습니다. 자세한 내용은 관리 여러 인텐트 및 활동세트 인텐트TaskStackBuilder 클래스 참조를 확인하세요.

categories

앱의 바로가기에서 실행하는 작업 유형의 그룹화를 제공합니다. 수행할 수 있습니다.

지원되는 단축어 카테고리 목록은 ShortcutInfo 클래스 참조

capability-binding

capability를 선언합니다. 바로가기로 연결됩니다.

이전 예에서 바로가기는 선언된 기능에 연결됩니다. 대상: CREATE_MESSAGE님, 앱 작업인 앱 작업 합니다. 이 기능 결합을 사용하면 사용자는 Google 어시스턴트가 바로가기를 호출합니다.

동적 바로가기 만들기

동적 바로가기는 내에서 컨텍스트에 민감한 특정 작업으로 연결되는 링크를 제공합니다. 있습니다. 이러한 작업은 앱을 사용하는 동안과 앱을 사용하는 동안에 바뀔 수 있습니다. 확인할 수 있습니다 동적 바로가기의 좋은 용도는 특정 사람에게 전화 걸기, 특정 위치로 이동하여 사용자의 마지막 저장 시점에서 게임 로드 있습니다. 동적 바로가기를 사용하여 대화를 열 수도 있습니다.

ShortcutManagerCompat Jetpack 라이브러리는 ShortcutManager API - 앱에서 동적 바로가기를 관리할 수 있습니다. ShortcutManagerCompat 라이브러리는 상용구 코드를 줄이고 단축키가 모든 Android 버전에서 일관되게 작동하는지 확인하세요. 이 라이브러리를 사용하여 동적 바로가기를 푸시할 수도 있습니다. Google 플랫폼(예: 어시스턴트)에 Google 바로가기 통합 라이브러리

ShortcutManagerCompat API를 사용하면 앱에서 다음 작업을 할 수 있습니다. 작업:

  • 푸시 및 업데이트: 사용 <ph type="x-smartling-placeholder">pushDynamicShortcut()</ph> 동적 바로가기를 게시하고 업데이트할 수 있습니다. 이미 동적 또는 ID가 동일한 고정된 바로가기가 있을 때마다 변경 가능한 각 바로가기가 업데이트됩니다.
  • 삭제: 다음을 사용하여 동적 바로가기 설정 삭제 removeDynamicShortcuts()입니다. 다음을 사용하여 모든 동적 바로가기 삭제: removeAllDynamicShortcuts()

바로가기에서 작업을 실행하는 방법에 대한 자세한 내용은 다음을 참조하세요. 바로가기 관리 및 <ph type="x-smartling-placeholder">ShortcutManagerCompat</ph> 참조

다음은 동적 바로가기를 만들어 앱:

Kotlin

val shortcut = ShortcutInfoCompat.Builder(context, "id1")
        .setShortLabel("Website")
        .setLongLabel("Open the website")
        .setIcon(IconCompat.createWithResource(context, R.drawable.icon_website))
        .setIntent(Intent(Intent.ACTION_VIEW,
                Uri.parse("https://www.mysite.example.com/")))
        .build()

ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)

자바

ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(context, "id1")
    .setShortLabel("Website")
    .setLongLabel("Open the website")
    .setIcon(IconCompat.createWithResource(context, R.drawable.icon_website))
    .setIntent(new Intent(Intent.ACTION_VIEW,
                   Uri.parse("https://www.mysite.example.com/")))
    .build();

ShortcutManagerCompat.pushDynamicShortcut(context, shortcut);

Google 바로가기 통합 라이브러리 추가

Google 바로가기 통합 라이브러리는 선택적인 Jetpack 라이브러리입니다. 그것은 를 사용하면 Android 표시 경로에 표시할 수 있는 동적 바로가기를 푸시할 수 있습니다. Google 표시 경로(예: 어시스턴트)에서 작동합니다. 이 라이브러리 사용 사용자가 바로가기를 찾아 특정 콘텐츠에 빠르게 액세스하거나 다시보기 가능 파악할 수 있습니다.

예를 들어 메시지 앱에서 연락처에 대한 동적 바로가기를 푸시할 수 있습니다. 이름이 'Alex'입니다. 메시지가 표시될 수 있습니다. 동적 바로가기 설정 후 사용자가 어시스턴트에게 "Hey Google, 알렉스에게 메시지 보내 줘"라고 요청하면 푸시됩니다. ExampleApp"이라고 하는 경우 어시스턴트가 ExampleApp을 실행하고 자동으로 구성할 수 있습니다. 알렉스에게 메시지를 보냅니다.

이 라이브러리로 푸시된 동적 바로가기에는 바로가기 제한 적용됩니다 이렇게 하면 앱이 단축키를 푸시할 때마다 사용자가 앱에서 관련된 액션을 완료할 때 이 바로가기를 자주 푸시하는 중 Google에서 사용자의 사용 패턴을 이해하고 상황에 따라 관련 바로가기를 제공합니다.

예를 들어 어시스턴트는 기기에서 푸시된 바로가기를 통해 학습할 수 있습니다. 피트니스 추적 앱인 피트니스 추적 앱 "달리기 시작" 제안 사용자가 휴대전화에서 휴대전화를 들어 있습니다.

Google 바로가기 통합 라이브러리는 주소 지정 가능한 어떠한 기능 자체에 문제가 있을 수 있습니다. 이 라이브러리를 앱에 추가하면 Google 표시 경로에서 ShortcutManagerCompat를 사용하여 앱이 푸시하는 바로가기에서

앱에서 이 라이브러리를 사용하려면 다음 단계를 따르세요.

  1. 지원하도록 gradle.properties 파일 업데이트 AndroidX 라이브러리:

          
          android.useAndroidX=true
          # Automatically convert third-party libraries to use AndroidX
          android.enableJetifier=true
          
          
  2. app/build.gradle에서 Google 바로가기 통합 라이브러리 및 ShortcutManagerCompat:

          
          dependencies {
            implementation "androidx.core:core:1.6.0"
            implementation 'androidx.core:core-google-shortcuts:1.0.0'
            ...
          }
          
          

Android 프로젝트에 라이브러리 종속 항목을 추가하면 앱에서 pushDynamicShortcut() 메서드 ShortcutManagerCompat하여 요건을 충족하는 동적 바로가기를 푸시할 수 있습니다. 런처 및 참여 Google 표시 경로에 표시할 수 있습니다.

<ph type="x-smartling-placeholder">

고정된 바로가기 만들기

Android 8.0(API 수준 26) 이상에서 고정된 바로가기를 만들 수 있습니다. 정적 및 동적 바로가기와 달리 고정된 바로가기는 지원되는 별도의 아이콘으로 사용합니다. 그림 1은 이러한 두 가지의 차이점을 보여줍니다. 사용할 수 있습니다.

<ph type="x-smartling-placeholder">

앱을 사용하여 지원되는 런처에 바로가기를 고정하려면 다음 단계를 따르세요.

  1. 사용 isRequestPinShortcutSupported() 기기의 기본 런처가 기본 런처의 인앱 고정을 지원하는지 단축키를 사용합니다.
  2. 다음 두 가지 방법 중 하나로 ShortcutInfo 객체를 만듭니다. 단축키의 존재 여부에 따라 달라집니다.

    1. 바로가기가 있으면 다음과 같은 ShortcutInfo 객체를 만듭니다. 에는 기존 바로가기의 ID만 포함됩니다. 시스템에서 바로가기와 관련된 기타 정보가 자동으로 표시됩니다.
    2. 새 바로가기를 고정하는 경우 ShortcutInfo을 만듭니다. 객체를 정의합니다. 단축키를 사용합니다.
    를 통해 개인정보처리방침을 정의할 수 있습니다. <ph type="x-smartling-placeholder">
  3. 다음을 호출하여 기기의 런처에 바로가기를 고정합니다. requestPinShortcut() 이 과정에서 PendingIntent 객체를 사용하면 바로가기가 고정된 경우에만 앱에 알립니다. 있습니다.

    <ph type="x-smartling-placeholder">

    바로가기가 고정되면 앱에서 updateShortcuts() 메서드를 사용하여 축소하도록 요청합니다. 자세한 내용은 업데이트 단축키를 사용하세요.

다음 코드 스니펫은 고정된 바로가기를 만드는 방법을 보여줍니다.

<ph type="x-smartling-placeholder">

Kotlin

val shortcutManager = getSystemService(ShortcutManager::class.java)

if (shortcutManager!!.isRequestPinShortcutSupported) {
    // Enable the existing shortcut with the ID "my-shortcut".
    val pinShortcutInfo = ShortcutInfo.Builder(context, "my-shortcut").build()

    // Create the PendingIntent object only if your app needs to be notified
    // that the user let the shortcut be pinned. If the pinning operation fails,
    // your app isn't notified. Assume here that the app implements a method
    // called createShortcutResultIntent() that returns a broadcast intent.
    val pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo)

    // Configure the intent so that your app's broadcast receiver gets the
    // callback successfully. For details, see PendingIntent.getBroadcast().
    val successCallback = PendingIntent.getBroadcast(context, /* request code */ 0,
            pinnedShortcutCallbackIntent, /* flags */ 0)

    shortcutManager.requestPinShortcut(pinShortcutInfo,
            successCallback.intentSender)
}

자바

ShortcutManager shortcutManager =
        context.getSystemService(ShortcutManager.class);

if (shortcutManager.isRequestPinShortcutSupported()) {
    // Enable the existing shortcut with the ID "my-shortcut".
    ShortcutInfo pinShortcutInfo =
            new ShortcutInfo.Builder(context, "my-shortcut").build();

    // Create the PendingIntent object only if your app needs to be notified
    // that the user let the shortcut be pinned. If the pinning operation fails,
    // your app isn't notified. Assume here that the app implements a method
    // called createShortcutResultIntent() that returns a broadcast intent.
    Intent pinnedShortcutCallbackIntent =
            shortcutManager.createShortcutResultIntent(pinShortcutInfo);

    // Configure the intent so that your app's broadcast receiver gets the
    // callback successfully. For details, see PendingIntent.getBroadcast().
    PendingIntent successCallback = PendingIntent.getBroadcast(context, /* request code */ 0,
            pinnedShortcutCallbackIntent, /* flags */ 0);

    shortcutManager.requestPinShortcut(pinShortcutInfo,
            successCallback.getIntentSender());
}
<ph type="x-smartling-placeholder">

맞춤 바로가기 활동 만들기

&#39;실행&#39;이라는 프롬프트를 표시하는 커스텀 대화상자 활동을 보여주는 이미지
  홈 화면에 Gmail 런처 아이콘을 추가하시겠습니까?&#39;라는 오류 메시지가 표시됩니다. 맞춤
  &#39;아니요&#39; 중에서 선택할 수 있습니다 &#39;아이콘 추가&#39;를 클릭합니다.
그림 2. 맞춤 앱 바로가기 대화상자 활동의 예

또한 사용자가 바로가기를 만드는 데 도움이 되는 특수한 활동을 만들 수 있습니다. 맞춤 옵션과 확인 버튼으로 완료할 수 있습니다 그림 2는 Gmail 앱에서의 활동 유형(예:

앱의 매니페스트 파일에 다음을 추가합니다. ACTION_CREATE_SHORTCUT 액티비티의 <intent-filter> 요소가 포함됩니다. 이 선언은 사용자가 로그인하려고 시도할 때 다음 동작을 설정합니다. 바로가기를 만들려면 다음 단계를 따르세요.

  1. 시스템에서 앱의 특수 활동을 시작합니다.
  2. 사용자가 바로가기 옵션을 설정합니다.
  3. 사용자가 확인 버튼을 선택합니다.
  4. 앱에서 createShortcutResultIntent() 메서드를 사용하여 축소하도록 요청합니다. 이 메서드는 Intent, 앱이 이전에 실행 중인 활동으로 다시 setResult()입니다.
  5. 앱에서 finish() 맞춤 바로가기를 만드는 데 사용된 활동

마찬가지로 앱에서 사용자에게 홈에 고정된 바로가기를 추가하라는 메시지를 표시할 수 있습니다. 앱이 처음 실행될 때 표시될 수 있습니다. 이 메서드는 사용자가 검색 기록의 일부로 바로가기를 만드는 데 도움이 되기 때문에 일반적인 워크플로에 따라 다릅니다

테스트 단축키

앱 바로가기를 테스트하려면 런처가 있는 기기에 앱을 설치하세요. 단축키를 지원합니다. 그후에 다음 작업을 실행합니다.

  • 터치 및 앱의 런처 아이콘을 길게 눌러 정의한 바로가기 보기 할 수 있습니다.
  • 바로가기를 드래그하여 기기의 런처에 고정합니다.