Android 파이어 베이스 Dynamic Link 사용하기

울늘·2022년 7월 4일
0

파이어베이스 공식문서에 정말 친절하게 하나부터 열까지 전부 알려주고 있지만 그래도 나처럼 헤매는 사람들이 있을 거라 생각하고 블로그를 써본다..

먼저!! dynamiclink sdk를 추가해준다.

dependencies {
    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:30.0.2')

    // Declare the dependencies for the Dynamic Links and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-dynamic-links-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
}

그 다음 내가 dynamick link를 사용하고 싶은 앱을 등록해줍니다~~
그리고 참여 -> dynamicklink를 클릭해줍니다.
그 다음 도메인을 등록해 주세요.
사용할 도메인을 입력하고 (고민하지 말고 firebase에서 제공해주는 도메인을 사용하면 됩니다.)
그 다음 프리픽스를 입력하라고 하는데 프리픽스는 원하는대로 설정해주면 됩니다.
이렇게 인증을 마치고 다음으로 넘어가면

이런 화면을 만나 볼 수 있는데 이러면 준비 끝입니다.
아 그리고 앱 등록했을 때 얻는 google-services.json파일은 프로젝트의 app파일 안에 넣어주면 됩니다.

그런 다음! 공식문서에 나와있는 대로 동적링크를 만들어주시면 됩니다.

private fun initDynamicLink(): Uri {
        val playStoreUri : Uri =Uri.parse(getString(R.string.play_store_example))
        val inviteCode = viewModel.inviteCode.value
        val dynamicLink = Firebase.dynamicLinks.dynamicLink {
            link = Uri.parse("https://example.com/?code=$inviteCode")
            domainUriPrefix = "https://example.page.link"
            androidParameters(requireContext().packageName) { fallbackUrl = playStoreUri }
            navigationInfoParameters { forcedRedirectEnabled = true }
        }
        val dynamicLinkUri = dynamicLink.uri
        Timber.d("dynamicUrl : $dynamicLinkUri")
        return dynamicLinkUri
    }

위 처럼 dynamic link를 생성할 수 있습니다. 여기서 prefix 와 link부분은 각자 작성해주세요 그리고 그 아래 파라미터들을 추가할 수 있는데 저는 링크를 클릭하였을 때 안드로이드 앱이 깔려있지 않다면 연결된 playstore링크로 이동하게끔 설정해 두었습니다. 파라미터에 관한 것은 공식링크를 참고하여 추가해주세요.
저렇게 생성된 dynamicLink를 웹에 복사해서 이동하게되면 앱이 열리면서 원하는 동작을 정의할 수 있습니다.

https://firebase.google.com/docs/dynamic-links/android/create?hl=ko#kotlin+ktx
https://anora.tistory.com/18

profile
주니어 안드로이드 개발자입니다!

0개의 댓글