์ฌ์ฉ์ ๊ฒฝํ์ ๊ฐ์ ํ๊ธฐ ์ํด ๊ฐ๋ฐ์๋ ์ฑ์์ ํน์ ์์ ์ ์คํํ๋ ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ์ ์ํ ์ ์์ต๋๋ค.
๊ฐ ๋ฐ๋ก๊ฐ๊ธฐ๋ ํ๋ ์ด์์ ์ธํ ํธ๋ฅผ ์ฐธ์กฐํ๋ฉฐ, ๊ฐ ์ธํ ํธ๋ ์ฌ์ฉ์๊ฐ ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ์ ํํ ๋ ์ฑ์์ ํน์ ์์ ์ ์คํํฉ๋๋ค.
์ฑ ๋ฐ๋ก๊ฐ๊ธฐ๋ 3๊ฐ์ง๊ฐ ์์ต๋๋ค.
| Shortcut Type | ์ค๋ช |
| Static Shortcuts | ์ฑ์ด ์ค์น๋ ๋ ๋ฏธ๋ฆฌ ์ ์๋, ๊ณ ์ ๋ ๋ฐ๋ก๊ฐ๊ธฐ |
| Dynamuc Shortcuts | ์ฑ ์คํ ์ค์ ๋์ ์ผ๋ก ์ถ๊ฐ/์ญ์ ํ ์ ์๋ ๋ฐ๋ก๊ฐ๊ธฐ |
| Pinned Shortcuts | ์ฌ์ฉ์๊ฐ ํ ํ๋ฉด์ ์ถ๊ฐํ ์ ์๋ ๋ฐ๋ก๊ฐ๊ธฐ |
์ด๋ ์ ์ ๋ฐ๋ก๊ฐ๊ธฐ์ ๋์ ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ํฌํจํ์ฌ ํ ๋ฒ์ ์ต๋ 4๊ฐ์ ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ํ์ํฉ๋๋ค. ๋ฐ๋ฉด ์ฌ์ฉ์๊ฐ ์ฑ์ ๋ง๋ค ์ ์๋ ๊ณ ์ ๋ฐ๋ก๊ฐ๊ธฐ์ ์๋ ์ ํ์ด ์์ต๋๋ค. ์ฑ์ ๊ณ ์ ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ์ญ์ ํ ์ ์์ง๋ง ์ฌ์ฉ ์ค์งํ ์๋ ์์ต๋๋ค.
Static Shortcuts(์ ์ ๋ฐ๋ก๊ฐ๊ธฐ)
์ ์ ๋ฐ๋ก๊ฐ๊ธฐ๋ ์ฑ์ด ์ค์น๋๋ ์๊ฐ๋ถํฐ ์กด์ฌํ๋ ๋ฐ๋ก๊ฐ๊ธฐ์ ๋๋ค. APK ๋๋ App Bundle๋ก ํจํค์ง๋ ๋ฆฌ์์ค ํ์ผ์ ์ ์๋ฉ๋๋ค.
์ฑ์ AndroidManifest.xml ํ์ผ์ ๋ฉํ๋ฐ์ดํฐ๋ก ์ฐ๊ฒฐ๋ shortcuts ๋ฆฌ์์ค๋ฅผ ์ ์ํ๋ฉด, ์๋๋ก์ด๋ ๋ฐ์ฒ๊ฐ ์ฑ์ ์ค์นํ ๋ ์ด๋ฅผ ์ฝ์ด๋ค์ฌ ์ฑ ์์ด์ฝ์ ๊ธธ๊ฒ ๋๋ ์ ๋ ๋ํ๋๋ ๋ฉ๋ด๋ก ๋ณด์ฌ์ค๋๋ค.
์ฆ, ์ฑ์ด ์ ๋ฐ์ดํธ๋๊ธฐ ์ ๊น์ง๋ ๊ฐ๋ฐ์๊ฐ ์ ์ํ ์ํ ๊ทธ๋๋ก ์ ์ง๋๊ณ , ์คํ ์ค์ ์ฝ๋๋ก ๋ฐ๊พธ๊ฑฐ๋ ์ง์ธ ์ ์์ต๋๋ค.
<!-- res/xml/shortcuts.xml-->
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="open_profile"
android:enabled="true"
android:icon="@drawable/ic_profile"
android:shortcutShortLabel="@string/shortcut_label"
android:shortcutLongLabel="@string/shortcut_label_long"
android:shortcutDisabledMessage="@string/shortcut_disabled_message">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.example.app"
android:targetClass="com.example.app.ProfileActivity" />
</shortcut>
</shortcuts>
android:enabled์ ๊ฐ์ true๋ก ์ค์ ํด์ผ ๋ฐ๋ก๊ฐ๊ธฐ๊ฐ ์ถ๊ฐ๋ฉ๋๋ค. false๋ก ์ค์ ํ๋ฉด ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ๋นํ์ฑํ ํ ์ ์์ต๋๋ค.
๋นํ์ฑํ๋ ์ด์ ๋ฅผ ์ค๋ช ํ๊ณ ์ ํ๋ค๋ฉด android:shortcutDisabledMessage๋ฅผ ์ค์ ํด์ผ ํฉ๋๋ค.
<!-- AndroidManifest.xml -->
<application ...>
<activity ...>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.shortcut"
android:resources="@xml/shortcuts" />
</activity>
</application>
์ด๋ ๋ฉํ๋ฐ์ดํฐ๋ application ๋ด๋ถ๊ฐ ์๋, intent-filter๊ฐ ์๋ Main Activity์ ์์ฑํด์ผ ์ ์์ ์ผ๋ก ๋์ํฉ๋๋ค.

์ด ๋ฐฉ์์ ์ฅ์ ์ ๊ฐ๋จํ๊ณ ์์ ์ ์ด๋ผ๋ ๊ฒ์ ๋๋ค. ์ฝ๋๋ฅผ ์ ํ ๊ฑด๋๋ฆฌ์ง ์๊ณ ๋ฆฌ์์ค ํ์ผ๋ง ์์ฑํ๋ฉด ๋ใ ๊ธฐ ๋๋ฌธ์ ๊ณ ์ ๋ ๊ธฐ๋ฅ์ด๋ ๋๊ตฌ์๊ฒ๋ ์ ๊ณต๋๋ ๊ณตํต ๊ธฐ๋ฅ์ ๋ฃ๊ธฐ์ ์ ํฉํฉ๋๋ค.
์๋ฅผ ๋ค๋ฉด ์ํ ์ฑ์ ๊ฒฝ์ฐ, "์ก๊ธํ๊ธฐ"๋ "๊ณ์ข์กฐํ"์ ๊ฐ์ ๊ณ ์ ๊ธฐ๋ฅ์ ๋ฑ๋กํ ์ ์์ต๋๋ค.
๋ฐ๋ฉด ๋จ์ ์ ๋์ ์ผ๋ก ๋ฐ๊ฟ ์ ์๋ค๋ ๊ฒ์ ๋๋ค. ๋ก๊ทธ์ธ ์ฌ๋ถ๋ ๊ฐ์ธํ๋ ๋ฐ์ดํฐ์ ๋ฐ๋ผ ๋ฌ๋ผ์ ธ์ผ ํ๋ ๋ฐ๋ก๊ฐ๊ธฐ๋ ์ด ๋ฐฉ์์ผ๋ก ๊ตฌํํ ์ ์์ต๋๋ค.
Dynamic Shortcuts(๋์ ๋ฐ๋ก๊ฐ๊ธฐ)
๋์ ๋ฐ๋ก๊ฐ๊ธฐ๋ ๋ฐํ์ ํ๊ฒฝ์์ ์ฝ๋๋ก ์ถ๊ฐํ๊ฑฐ๋ ์์ , ์ญ์ ํ ์ ์๋ ๋ฐ๋ก๊ฐ๊ธฐ์ ๋๋ค.
์ฑ์์ ShortManager API๋ฅผ ์ด์ฉํด ๋ฐํ์ ์์ ์ ์ ๋จ์ถํค๋ฅผ ๋ฑ๋กํ ์ ์๊ณ , ์ฑ ์ํ๋ ์ฌ์ฉ์ ํ๋์ ๋ฐ๋ผ ์ ์ฐํ๊ฒ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
val intent = Intent(this, ProfileActivity::class.java).apply {
action = Intent.ACTION_VIEW
}
val shortcut = ShortcutInfoCompat.Builder(this, "dynamic_profile")
.setShortLabel("ํ๋กํ2")
.setIcon(Icon.createWithResource(this, R.drawable.ic_profile))
.setIntent(intent)
.build()
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
pushDynamicShortcut() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋์ผํ ID์ ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ์ ๋ฐ์ดํธํ๊ณ , ๋์ผํ ID๊ฐ ์์ ๊ฒฝ์ฐ์๋ ์๋ก์ด ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ์ถ๊ฐํฉ๋๋ค.

์ถ๊ฐํ ๋ฐ๋ก๊ฐ๊ธฐ๋ ์๋์ ๋ฉ์๋๋ฅผ ํธ์ถํ์ฌ ์ญ์ ํ ์ ์์ต๋๋ค.
// id๋ฅผ ์ฌ์ฉํด ํน์ ๋ฐ๋ก๊ฐ๊ธฐ ์ญ์
ShortcutManagerCompat.removeDynamicShortcuts(context, "dynamic_profile")
// ๋ชจ๋ ๋ฐ๋ก๊ฐ๊ธฐ ์ญ์
ShortcutManagerCompat.removeAllDynamicShortcuts(context)
์ด ๋ฐฉ์์ ์ฅ์ ์ ์ ์ฐํจ์ผ๋ก, ์ฌ์ฉ์์ ํ๋์ ๋ง์ถฐ ๊ฐ์ธํ๋ ๊ฒฝํ์ ์ ๊ณตํ ์ ์์ต๋๋ค. ํ์ง๋ง ์ฑ์ด ์ข ๋ฃ๋๊ฑฐ๋ ์บ์๊ฐ ์ง์์ง๋ฉด ๋ฑ๋ก๋ ๋์ ๋ฐ๋ก๊ฐ๊ธฐ๊ฐ ์ฌ๋ผ์ง ์ ์๊ณ , ๊ธฐ๋ณธ์ ์ผ๋ก๋ ์ฑ ์คํ ์ค์๋ง ์๋ฏธ๊ฐ ์๋ ๊ธฐ๋ฅ์ด๋ผ๋ ์ ์ด ๋จ์ ์ ๋๋ค.
Pinned Shortcuts(๊ณ ์ ๋ฐ๋ก๊ฐ๊ธฐ)
๊ณ ์ ๋ฐ๋ก๊ฐ๊ธฐ๋ ํ ํ๋ฉด์ ๋ ๋ฆฝ์ ์ธ ์์ด์ฝ์ฒ๋ผ ์ถ๊ฐ๋๋ ๋ฐ๋ก๊ฐ๊ธฐ์ ๋๋ค. ์ฌ์ฉ์๊ฐ ๊ถํ์ ๋ถ์ฌํ๋ฉด ๋ฐํ์ ์ ์ง์๋๋ ๋ฐ์ฒ์ ์ถ๊ฐํ ์ ์์ต๋๋ค.
์ฑ ๋ด๋ถ์์ ShortcutManager์ requestPinShortcut() ๋ฉ์๋๋ฅผ ํธ์ถํ๋ฉด ์์คํ ์ด ์ฌ์ฉ์์๊ฒ ํ ํ๋ฉด์ ๋ฐ๋ก๊ฐ๊ธฐ๋ฅผ ์ถ๊ฐํ ๊ฒ์ธ์ง์ ๋ํ ํ์ ์ ๋์์ฃผ๊ณ , ์ฌ์ฉ์๊ฐ ๋์ํ๋ฉด ํด๋น ์์ด์ฝ์ด ํ ํ๋ฉด์ ๊ณ ์ ๋ฉ๋๋ค.
val shortcutManager = getSystemService(ShortcutManager::class.java)
if (shortcutManager.isRequestPinShortcutSupported) {
val intent = Intent(this, ProfileActivity::class.java).apply {
action = Intent.ACTION_VIEW
}
val shortcut = ShortcutInfo.Builder(this, "pinned_profile")
.setShortLabel("ํ๋กํ3")
.setIcon(Icon.createWithResource(this, R.drawable.ic_profile))
.setIntent(intent)
.build()
val pinIntent = shortcutManager.createShortcutResultIntent(shortcut)
val callbackIntent = PendingIntent.getBroadcast(this, 0, pinIntent, PendingIntent.PLAG_IMMUTABLE)
shortcutManager.requestPinShortcut(shortcut, callbackIntent.intentSender)
}


์ด ๋ฐฉ์์ ์ฅ์ ์ ํ ํ๋ฉด ์ ๊ทผ์ฑ์ด ๊ทน๋ํ๋๋ค๋ ์ ์ ๋๋ค. ์ฌ์ฉ์๊ฐ ์์ฃผ ์ด์ฉํ๋ ํน์ ๊ธฐ๋ฅ์ ์์ด์ฝ์ฒ๋ผ ๋ฐฐ์นํ ์ ์์ด์ ์ฌ์ฉ์ ๊ฒฝํ์ด ๊ฐ์ ๋ฉ๋๋ค.
Built-in Intents(๋ด์ฅ ์ธํ ํธ)
์ด๋ ๋ฐ๋ก๊ฐ๊ธฐ์ Capability ์์๋ฅผ ์ถ๊ฐํ๋ฉด Google ์ด์์คํดํธ๋ฅผ ํ์ฉํด ์ฌ์ฉ์๊ฐ ๊ธฐ๋ฅ์ ์ ์ดํ ์ ์์ต๋๋ค.
์ด๋ฅผ ๋ด์ฅ ์ธํ ํธ(Built-in Intents)๋ผ๊ณ ํฉ๋๋ค.
์ฌ์ฉ์๊ฐ ์ฑ์ ๊ธธ๊ฒ ๋๋ฅด๊ฑฐ๋ ๋ฐ์ฒ์์ shortcut๋ฅผ ์ง์ ๋๋ฌ intent๋ฅผ ์คํํ๋ ๊ฒ์ด ์๋๋ผ, ์์ฑ ๋ช ๋ น๊ณผ ๊ฐ์ด ์ด์์คํดํธ๊ฐ BII๋ฅผ ํธ์ถํ์ฌ ํด๋น shortcut๊ณผ ์ฐ๊ฒฐ๋ Intent๋ฅผ ์คํํ๋ ๋ฐฉ์์ ๋๋ค.
์๋์ ์๋ ์ฌ์ฉ์๊ฐ ์์ฑ ๋ช ๋ น์ผ๋ก ์ด์์คํดํธ๋ฅผ ์ฌ์ฉํด ํผํธ๋์ค ์ฑ์์ ์ด๋์ ์์ํ๋๋ก ์ง์ํ๋ ๋ฐฉ๋ฒ์ ๋๋ค.
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<capability android:name="actions.intent.START_EXERCISE">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example.sampleApp"
android:targetClass="com.example.sampleApp.ExerciseActivity">
<parameter
android:name="exercise.name"
android:key="exerciseType"/>
</intent>
</capability>
</shortcuts>
<capability>์ name ์์ฑ์ ์ง์ํ ์์ ์์ฑ ๋ช ๋ น์ด์ ๋ํ BII Action ID๋ฅผ ์ ์ํฉ๋๋ค.
์ด์์คํดํธ๊ฐ "Hey Google, ์ด๋์ ์์ํด์ค." ๊ฐ์ ๋ช ๋ น์ด๋ฅผ ์ด ์ฑ์ ๋งคํํ๋ ค๊ณ ํ ๋ START_EXERCISE BII๋ฅผ ์ฌ์ฉํฉ๋๋ค.
<parameter>์๋ ๊ธฐ๋ฅ๊ณผ ์ฐ๊ฒฐ๋ ๋งค๊ฐ๋ณ์๋ฅผ ๋ช ์ํฉ๋๋ค.
์๋ฅผ ๋ค์ด ์ฌ์ฉ์๊ฐ "์ฑ์์ ๋ฌ๋ฆฌ๊ธฐ ์์ํด์ค." ๋ผ๊ณ ํ์ ๋ '๋ฌ๋ฆฌ๊ธฐ'๋ผ๋ ๋งค๊ฐ๋ณ์๊ฐ ํ์ํฉ๋๋ค. ์ด๋ฌํ ๊ฐ์ parameter ์์์ ์ ์ํฉ๋๋ค.
๋์ ๋ฐ๋ก๊ฐ๊ธฐ๋ ๊ณ ์ ๋ฐ๋ก๊ฐ๊ธฐ์ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด capability๋ฅผ ์ค์ ํฉ๋๋ค.
val shortcut = ShortcutInfoCompat.Builder(context, "shortcut_id")
.setShortLabel("๋ฌ๋ฆฌ๊ธฐ ์์")
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_run))
.setIntent(intent)
.addCapabilityBinding(
"actions.intent.START_EXERCISE",
"exercise.name",
listOf("running")
)
.build()
์ฌ๋ฌ ๋ช ๋ น์ด์ ๋งค๊ฐ๋ณ์์ ๊ดํ ์ ๋ณด๋ App Actions built-in intents์์ ํ์ธํ ์ ์์ต๋๋ค.
์๋๋ก์ด๋ ๊ฐ๋ฐ์ ๋ก๋๋งต์ ๋ฐ๋ผ ์ ๋ฆฌํ ๋ด์ฉ์ ๋๋ค.
'๐ป Programming > Android Developer AtoZ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Android] App Components - (6) Intent ์๋ฒฝ ๊ฐ์ด๋ (1) | 2025.03.24 |
|---|---|
| [Android] App Components - (5) Content Provider ์๋ฒฝ ๊ฐ์ด๋ (2) | 2025.03.24 |
| [Android] App Components - (4) Broadcast Receiver ์๋ฒฝ ๊ฐ์ด๋ (0) | 2025.03.21 |
| [Android] App Components (3) - Service ์๋ฒฝ ๊ฐ์ด๋ (1) | 2025.03.19 |
| [Android] App Components (2) - Activity ์๋ฒฝ ๊ฐ์ด๋ (1) | 2025.03.05 |