Android 앱 스킴(App Scheme) 호출하는 방법 (App to App 호출 및 Web To App 호출)

✨ 개요

앱을 개발하다 보면 앱 → 앱 또는 웹 → 앱으로 사용자를 자연스럽게 이동시켜야 할 때가 많습니다.

예를 들어,

이때 사용하는 것이 바로 앱 스킴(App Scheme, URL Scheme) 또는 딥링크(Deeplink)입니다.


1. ✅ 앱 스킴이란?

앱 스킴은 URI 형식을 통해 앱을 직접 실행하거나 특정 화면으로 이동시키는 방식입니다.

예시 URI:


2. ✅ 앱 스킴 설정 방법

2.1 AndroidManifest.xml 설정

<activity
        android:name=".MainActivity"
        android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
                android:host="post"
                android:scheme="myapp" />
    </intent-filter>
</activity>

2.2 호출되는 App 코드

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

    handleDeeplink(intent)
}

private fun handleDeeplink(intent: Intent) {
    Log.e(TAG, "handleDeeplink ${intent.data}")
    val uri = intent.data ?: return

    // "myapp://post/detail?id=1234&author=kim"
    val id = uri.getQueryParameter("id")     // "1234"
    val author = uri.getQueryParameter("author") // "kim"
    val path = uri.path                      // "/detail"
    val host = uri.host                      // "post"

    Log.e(TAG, "deepLinkData host=$host path=$path")
    Log.e(TAG, "deepLinkData id=$id author=$author")
}

3. ✅ App 호출하는 방법

3.1 App to App 스킴 호출 방법

private fun appToAppScheme() {
    val uri = Uri.parse("myapp://post/detail?id=1234&author=kim")
    val intent = Intent(Intent.ACTION_VIEW, uri)
    startActivity(intent)
}

3.2 Web to App 스킴 호출 방법

location.href = "myapp://post/detail?id=1234&author=kim";
  setTimeout(function () {
    // 설치 페이지로 이동시키고 싶은 경우
    location.href = "https://play.google.com/store/apps/details?id=com.example.myapp";
  }, 1500);

4.🧠 결론

앱 스킴(App Scheme)을 활용하면 앱 간의 연결성은 물론, 웹과 앱을 유연하게 연결할 수 있어 사용자 경험을 향상시킬 수 있습니다.

📱 앱 설치 유도부터 특정 화면 진입까지, 앱 스킴을 활용해보세요!



Related Posts