본문 바로가기
🖥 Programming/📱 Android (Kotlin)

[Andorid][kotlin] DeepLink 딥링크 알아보기 - 1편

by MinChan-Youn 2022. 2. 22.

안녕하세요! 챠니입니다~

오늘은 DeepLink(딥링크)에 대해서 한번 알아보겠습니다~

 

딥링크란 무엇인가?

딥링크란 모바일 어플리케이션의 특정 페이지에 도달 할 수 있는 링크를 말합니다.

여기서 알아야하는 점은 웹(www) 어플리케이션이 http:// 또는 https:// 프로토콜을 가지고 있는 것 처럼 모바일 어플리케이션에도 각자의 프로토콜을 가지고 있다는 점입니다.

 

그래서 우리는 이러한 각 앱의 딥링크를 설정함으로써 내가 설정한 앱으로 바로 이동할 수 있도록 도와주는 역할을 하게 되는 것입니다!

 

 

딥링크

왜 사람들은 딥링크에 대해서 주목을 할까요?

그것은 바로 빅데이터 시대에서 데이터는 곧 경쟁력이기 때문입니다. 하나하나 검색하면서 이동하는 경우도 있지만 이제는 그런 부분을 바로바로 제공 할 수 있는 편리한 서비스를 계획하다보니 딥링크도 나온 부분이 아닐까 싶어요~

 

URI 스킴 방식은 Scheme://Path라는 두개의 요소로 구성됩니다.
  • Scheme://Path
  • Scheme = 앱을 특정함 (트위터)
  • Path = 앱 내 페이지를 특정함 (트위터 내 회원가입 페이지)

 

딥링크에서는 가장크게 호출과 수신부분으로 나뉠 수 있는데요~

호출 및 수신 모두 간단한 앱을 만들어서 확인을 해보는 시간을 가져보도록 하겠습니다~

어렵지 않으니 하나하나 차근차근보면서 따라오세요~

 

 

이번 1편에서는 호출하는 앱을 만들어 보면서 어떻게 딥링크 URL을 호출하는지에 대해서 알아보도록 하겠습니다!

1. DeepLink 호출

 

MainActivity.kt

class MainActivity : AppCompatActivity() {
    lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        /** ViewBinding 설정 */
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        /** Click-Listener */
        binding.tvDeepLink.setOnClickListener {
            try {
                var url = "deeplink://host?data1=DeepLinkData1&data2=DeepLinkData2"
                var intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
                intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK //새로운 창
                startActivity(intent)
            } catch (e: Exception) {
                e.printStackTrace()
                /** 딥링크 호출 오류(해당 앱이 존재하지 않을 경우)*/
                Toast.makeText(this, "DeepLink 호출이 불가능 합니다.", Toast.LENGTH_SHORT).show()
            }
        }
    }
}

 

딥링크를 호출하는 코드를 보면서 설명해 보도록 하겠습니다.

저는 deeplink라는 앱을 특정하는 부분을 작성하고, host라는 앱 내 페이지를 지정하고 그 뒤로 data1, data2라는 딥링크를 만들어 보았습니다.

 

 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tv_deepLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00FFFF"
        android:padding="20dp"
        android:text="DeepLink 호출"
        android:textColor="#000000"
        android:textSize="20dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

 

build.gradle(:app)

...

	// ViewBinding 설정
    buildFeatures {
        viewBinding true
    }
    
...

 

 

여기까지 딥링크를 호출하는 호출앱을 간단하게 만들어 보았습니다. 다음은 딥링크를 수신하는 앱을 만들어 보도록 하겠습니다.

 

앱 화면

여기까지 따라오셨다면 여러분은 딥링크에 대해서 조금 더 이해를 하셨다고 볼 수 있습니다.

완성된 앱을 사진을 통해서 보도록 하겠습니다.

 

딥링크 호출 앱

 

 

글 정리 & 소스코드

[정리]

딥링크 호출: https://minchanyoun.tistory.com/96

딥링크 수신: https://minchanyoun.tistory.com/97

 

[Andorid][kotlin] DeepLink 딥링크 알아보기 - 1편

안녕하세요! 챠니입니다~ 오늘은 DeepLink(딥링크)에 대해서 한번 알아보겠습니다~ 딥링크란 무엇인가? 딥링크란 모바일 어플리케이션의 특정 페이지에 도달 할 수 있는 링크를 말합니다. 여기서

minchanyoun.tistory.com

 

[소스코드]
호출: https://github.com/younminchan/kotlin-study/tree/main/DeepLinkCall_kotlin

수신: https://github.com/younminchan/kotlin-study/tree/main/DeepLinkreceive_kotlin

 

GitHub - younminchan/kotlin-study: kotlin-example

kotlin-example. Contribute to younminchan/kotlin-study development by creating an account on GitHub.

github.com

 

 

질문 또는 궁굼한 부분은 댓글을 남겨주세요! 친절하게 답변드리겠습니다!

응원의 댓글은 저에게 큰 힘이 된답니다! :)

즐거운 하루되세요!