从Kotlin的Deeplink网址中提取查询参数

时间:2020-11-01 08:17:08

标签: java firebase kotlin firebase-dynamic-links query-parameters

请帮助大家,我正在使用Firebase动态链接,我想知道我们如何提取Kotlin中的传递字符串queryparameters。这是生成的深度链接:

deeplink = https://demo.com/?roomCode=myroomtest%3FroomToken%3DOiJIUzI1NiJ

如何从Deeplink网址中提取roomCode = myroomtest,roomToken = OiJIUzI1NiJ此字符串值。

private fun handleDynamicLink() {
    Firebase.dynamicLinks
        .getDynamicLink(intent)
        .addOnSuccessListener { pendingDynamicLinkData ->
            val deepLink: Uri?
            if (pendingDynamicLinkData != null) {
                deepLink = pendingDynamicLinkData.link
            
  what queryparameter should i use here to extract the strings from deeplink?

            }
        }
        .addOnFailureListener { _ ->
            toast(getString(R.string.main_error_fetch_dynamic_link))
        }
}

我需要字符串,以便可以使用以下代码开始开会:

 private fun joinMeeting (roomCode:String, roomToken:String) {
    MeetingUtils.startMeeting(
        this,
        roomCode,
        roomToken)
}

1 个答案:

答案 0 :(得分:0)

最后解决:

             private fun handleDynamicLink() {
    Firebase.dynamicLinks
        .getDynamicLink(intent)
        .addOnSuccessListener { pendingDynamicLinkData ->
            val deepLink: Uri?
                if (pendingDynamicLinkData != null) {
                    deepLink = pendingDynamicLinkData.link

val roomCode = deepLink?.getQueryParameter("roomCode")?.substringBefore("?roomToken=","")

val roomToken = deepLink?.getQueryParameter("roomCode")?.replace("roomToken","roomToken")?.substringAfter("?roomToken=","")

                    if(roomCode !=null && roomToken != null) {
                        joinMeeting(roomCode, roomToken)
                    }


                }
        }
        .addOnFailureListener { _ ->
            toast(getString(R.string.main_error_fetch_dynamic_link))
        }
}