ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [AOS] Android DeepLink ์„ค์ •
    2022. 11. 23. 15:59
    ๋ฐ˜์‘ํ˜•

     

     

     

    ๐Ÿฑ
    ์˜ค์†Œ๋ฆฌ๋‹˜, ๋”ฅ๋งํฌ๋กœ MainActivity๋ฅผ ๋„์›Œ์ฃผ์‹œ๊ณ , name ๊ฐ’์„ ๋ฐ›๊ฒŒ ๊ตฌํ˜„ํ•ด์ฃผ์„ธ์š”~
    ๋”ฅ๋งํฌ... ๊ฐ€ ๋ชจ์ฃ ...?
    ๐Ÿถ

     

     

     

    ๐Ÿฑ
    ๊ตฌํ˜„ํ•ด์ฃผ์„ธ์š”.
    ๋„ค...
    ๐Ÿถ

     

     

     

     

     

    ๋”ฅ๋งํฌ๋ž€

    ๋”ฅ ๋งํฌ๋Š” ์‚ฌ์šฉ์ž๋ฅผ ์•ฑ์˜ ํŠน์ • ์ฝ˜ํ…์ธ ๋กœ ๋ฐ”๋กœ ์—ฐ๊ฒฐํ•˜๋Š” URL์ด๋‹ค.

    ์—ฐ๊ฒฐ์„ ์›ํ•˜๋Š” activity์˜ intent filter์— ๋”ฅ ๋งํฌ๋ฅผ ์„ค์ •ํ•˜๋ฉด deeplink๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ์šฉ์ž์—๊ฒŒ ํ•ด๋‹น activity๋ฅผ ๋„์›Œ์ค€๋‹ค.

     

     

    ๋”ฅ๋งํฌ ๋งŒ๋“ค๊ธฐ

     

    ์•ฑ ์ฝ˜ํ…์ธ  ๋”ฅ ๋งํฌ ๋งŒ๋“ค๊ธฐ  |  Android ๊ฐœ๋ฐœ์ž  |  Android Developers

    ์‚ฌ์šฉ์ž๊ฐ€ ๋งํฌ์—์„œ ์•ฑ์— ์ง„์ž…ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋ ค๋ฉด ๊ด€๋ จ ํ™œ๋™์˜ ์ธํ…ํŠธ ํ•„ํ„ฐ๋ฅผ ์•ฑ manifest์— ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ธํ…ํŠธ ํ•„ํ„ฐ๋Š” ๋ชจ๋“  ํ™œ๋™์˜ ์ฝ˜ํ…์ธ ๋กœ ์—ฐ๊ฒฐ๋˜๋Š” ๋”ฅ ๋งํฌ๋ฅผ ํ—ˆ์šฉ…

    developer.android.com

     

     

    1. ์ปค์Šคํ…€ scheme, host ๊ฐ’ ์ •์˜

    ํŽธ์˜๋ฅผ ์œ„ํ•ด string.xml์— scheme๊ณผ host ๊ฐ’์„ ์ •์˜ํ•ด์ค€๋‹ค.

     

    <resources>
    	...
        <string name="deeplink_scheme">deeplink</string>
        <string name="deeplink_host">main</string>
    </resources>

     

     

    2. AndroidMenifest.xml ์„ค์ •

    ๋”ฅ๋งํฌ์— ์—ฐ๊ฒฐ๋˜์–ด ํ™”๋ฉด์— ์ถœ๋ ฅํ•  activity์— VIEW action๊ณผ BROWSSABLE, DEFAULT ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ํฌํ•จํ•œ๋‹ค.

    ๋˜ํ•œ URI ํ˜•์‹์„ ๋‚˜ํƒ€๋‚ด๋Š” data ํƒœ๊ทธ์— ์œ„์—์„œ ์ •์˜ํ•œ scheme๊ณผ host๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.

     

    <application
    	...>
        <activity
        	...>
            <intent-filter>
            	<action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
    
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
    
                <data android:host="@string/deepilnk_host"
                    android:scheme="@string/deeplink_scheme" />
            </intent-filter>
        </activity>
        ...
    </application>

     

     

     

    Deeplink ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ธฐ

    * ์—๋ฎฌ๋ ˆ์ดํ„ฐ๋ฅผ ์ด์šฉํ•œ ํ…Œ์ŠคํŠธ ์ž…๋‹ˆ๋‹ค.

     

     

    Android ๋””๋ฒ„๊ทธ ๋ธŒ๋ฆฌ์ง€(adb)  |  Android ๊ฐœ๋ฐœ์ž  |  Android Developers

    ๊ธฐ๊ธฐ์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•˜๋Š” ๋‹ค๋ชฉ์  ๋ช…๋ น์ค„ ๋„๊ตฌ์ธ Android ๋””๋ฒ„๊ทธ ๋ธŒ๋ฆฌ์ง€์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์„ธ์š”.

    developer.android.com

     

     

    Android Studio ํ•˜๋‹จ์˜ Terminal์„ ์ด์šฉํ•˜๋ฉด ๋œ๋‹ค.

     

     

    1. ์‹คํ–‰๋˜์–ด ์žˆ๋Š” ์—๋ฎฌ๋ ˆ์ดํ„ฐ ํ™•์ธํ•ด๋ณด๊ธฐ

     

    $  adb devices
      List of devices attached
      emulator-5556 device

     

    ์—๋ฎฌ๋ ˆ์ดํ„ฐ๊ฐ€ ์‹คํ–‰๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ

    $  adb devices
      adb: device offline

     

    ์œ„์™€ ๊ฐ™์ด ์‹คํ–‰๋˜์–ด ์žˆ๋Š” ์—๋ฎฌ๋ ˆ์ดํ„ฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ ๋‹นํ™ฉํ•˜์ง€ ์•Š๊ณ  ์—๋ฎฌ๋ ˆ์ดํ„ฐ๋ฅผ ์ผœ์ฃผ๋ฉด ๋œ๋‹ค.

     

     

    ์ขŒ์ธก ์ƒ๋‹จ์—์„œ ์—๋ฎฌ๋ ˆ์ดํ„ฐ๋ฅผ ์„ ํƒ ํ›„ ์‹คํ–‰ํ•ด์ฃผ๊ฑฐ๋‚˜

     

    ์ƒ๋‹จ ์ขŒ์ธก Device Manager ํƒญ์—์„œ ์—๋ฎฌ๋ ˆ์ดํ„ฐ๋ฅผ ์‹คํ–‰ํ•ด์ค€๋‹ค.

     

     

    ์‹คํ–‰๋˜์–ด ์žˆ๋Š” ์—๋ฎฌ๋ ˆ์ดํ„ฐ๊ฐ€ ์—ฌ๋Ÿฌ๋Œ€์ธ ๊ฒฝ์šฐ

    $  adb devices
      List of devices attached
      emulator-5556 device
      emulator-5558 device

     

     

    ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ด ํŠน์ • ์—๋ฎฌ๋ ˆ์ดํ„ฐ shell์—์„œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.

     

    $  adb -s emulator-5556 shell

     

     

     

    2. deeplink ์‹คํ–‰ ๋ช…๋ น์–ด

     

    $   adb shell am start -W -a android.intent.action.VIEW -d "deeplink://main?name=test!!" com.๋”ฅ๋งํฌ.ํ”„๋กœ์ ํŠธ.ํŒจํ‚ค์ง€๋ช…
      Starting: Intent { act=android.intent.action.VIEW dat=test://main?name=test!! pkg=com.๋”ฅ๋งํฌ.ํ”„๋กœ์ ํŠธ.ํŒจํ‚ค์ง€๋ช… }
      Status: ok
      LaunchState: WARM
      Activity: com.๋”ฅ๋งํฌ.ํ”„๋กœ์ ํŠธ.ํŒจํ‚ค์ง€๋ช….activity.MainActivity
      TotalTime: 907
      WaitTime: 914
      Complete

     

    ์ค‘๊ฐ„์˜ "deeplink://main?name=test!!" ์—์„œ

    deeplink๋Š” ์œ„์—์„œ string.xml์— ์ •์˜ํ•œ scheme๊ฐ’, main์€ host ๊ฐ’์ด๋‹ค.

    name=test!!๋Š” ํ•ด๋‹น activity์— ์ „๋‹ฌํ•  ๋ฐ์ดํ„ฐ, ์ฆ‰ name์ด๋ผ๋Š” intent์— test!!๋ผ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•ด ์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

     

     

    $   adb shell am start -W -a android.intent.action.VIEW -d "deeplink://main?name=test!!" com.๋”ฅ๋งํฌ.ํ”„๋กœ์ ํŠธ.ํŒจํ‚ค์ง€๋ช…
      adb: more than one device/emulator

     

    ๋ช…๋ น์–ด ์‹คํ–‰ ํ›„ ์œ„์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์œ„์—์„œ ์–ธ๊ธ‰ํ•œ ์‹คํ–‰๋˜์–ด ์žˆ๋Š” ์—๋ฎฌ๋ ˆ์ดํ„ฐ๊ฐ€ ์—ฌ๋Ÿฌ๋Œ€์ธ ๊ฒฝ์šฐ์ด๊ธฐ ๋•Œ๋ฌธ์— ํŠน์ • ์—๋ฎฌ๋ ˆ์ดํ„ฐ shell์—์„œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

     

     

     

    ์„ค์ •ํ•œ deeplink์˜ scheme์ด ๋‹ค๋ฅธ ์•ฑ๊ณผ ๊ฒน์น˜๋ฉด

     

    market์ด๋ผ๋Š” ์ด๋ฆ„์˜ scheme์ด ๊ฒน์นœ ๊ฒฝ์šฐ

     

     

     

    ์œ„์™€ ๊ฐ™์ด ๋”ฅ๋งํฌ๊ฐ€ ์ผ์น˜ํ•˜๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜๋“ค ์ค‘์—์„œ ์›ํ•˜๋Š” ์•ฑ์„ ์„ ํƒํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•˜๊ธฐ๋„ ํ•œ๋‹ค.

    ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์€ ๋”ฅ๋งํฌ์˜ ์ผ์ข…์ธ ์•ฑ๋งํฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

    ์•ฑ๋งํฌ๋Š” ๋„๋ฉ”์ธ ์ฃผ์†Œ๋ฅผ ์ด์šฉํ•œ ๋”ฅ๋งํฌ๋กœ, ์œ„์—์„œ ๋‹ค๋ฃฌ ์Šคํ‚ด์„ ์ด์šฉํ•œ ๋”ฅ๋งํฌ๋ฅผ ๋“ฑ๋กํ•˜๋Š” ๊ฒƒ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ AndroidMenifest์—์„œ ํ•ด๋‹น activity์— intent-filter๋ฅผ ์„ค์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

    ์•ฑ๋งํฌ ์™ธ์—๋„ ์œ ๋‹ˆ๋ฒ„์…œ ๋งํฌ๊ฐ€ ์žˆ๋‹ค.

    ํ•˜๋‚˜์˜ ๋”ฅ๋งํฌ๋งŒ์œผ๋กœ๋Š” ๋ชจ๋“  ํ™˜๊ฒฝ์— ๋Œ€์‘ํ•˜์ง€ ๋ชปํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ตœ์ ์˜ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ์œ„ํ•ด์„œ๋Š” 3๊ฐœ์˜ ๋”ฅ๋งํฌ ๋ฐฉ์‹์„ ์ฑ„ํƒํ•˜์—ฌ ์ƒํ˜ธ ๋ณด์™„์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

     

     

     

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€

Designed by Tistory.