wintertreey 님의 블로그

커스텀 링크 본문

모바일 앱/Kotlin

커스텀 링크

wintertreey 2025. 10. 23. 14:28

웹사이트나 쇼핑몰에서 결제시 이미 설치해둔 개개인의 결제앱으로 넘어가는 과정을 떠올려보자.

이렇게 외부에서 해당 앱의 어떤 화면으로 이동하려면, 해당 앱 내에 커스텀 링크에 관한 정보가 존재해야한다.

 

앱 리뉴얼 작업을 시행하면서 앱을 시작부터 작업할 수 있게 되어서 이참에 해당 앱의 커스텀 링크를 모두 만들어두고자 하기로 마음먹었다.

 

Android는 App Link, IOS는 Universial Link로 나뉘어진다.

나의 경우에는 간단히 커스텀 링크로 작업했다. 

 

해당 앱의 AndroidManifest.xml 쪽에 intent-filter를 추가한다.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.company.myapp">

    <application
        android:name=".MyApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher">

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTask"
            android:theme="@style/Theme.App">

            <!-- 일반 앱 실행용 -->
            <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:scheme="myapp"
                    android:host="open" />
            </intent-filter>

            <!-- ✅ (선택) App Link 방식 (도메인 기반으로 앱 실행) -->
            <!--
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="https"
                    android:host="myapp.company.com"
                    android:pathPrefix="/open" />
            </intent-filter>
            -->
        </activity>
    </application>
</manifest>

 

이 경우 스킴은 myapp://open이다.

 

앱을 설치한 상태에서 테스트하는 방법

1. 실제 기기 브라우져에서 테스트

기기에 앱이 설치된 상태에서 chrome 주소창에 다음과같이 입력 후 이동했을때, 앱이 열리면 성공.

tmapp://open

 

2. PC 연결 후 실행 

adb 명령으로 직접 테스트하면 된다.

1) Android SDK Platform Tools 설치하기

https://developer.android.com/studio/releases/platform-tools

 

SDK 플랫폼 도구 출시 노트  |  Android Studio  |  Android Developers

Android SDK 플랫폼 도구는 Android SDK의 구성요소입니다.

developer.android.com

압축을 풀어보면 폴더 안에 adb.exe 파일이 있음을 확인할 수 있다.

 

# 1. adb.exe가 존재하는 폴더로 이동
cd /d D:\down\platform-tools-latest-windows\platform-tools
# 현재 드라이브가 다른경우(C드라이브->D드라이브로) 옵션을 붙여 드라이브까지 바꿔서 이동해주었다. 

# 2. 기기 연결 확인
adb devices

# 3. 앱 링크 테스트 실행
adb shell am start -a android.intent.action.VIEW -d "myapp://open"

 

 

'모바일 앱 > Kotlin' 카테고리의 다른 글

생명 주기 함수  (0) 2025.10.23
[kotlin] 스톱워치 구현하기  (3) 2025.07.25