0

From my app I scan a QRcode from a website to make the same user login on the app. My approach now:

I open the qr code result : // https://example.page.link/g8uj79dsfsdfy8qrf5Bp6

   val openURL = Intent(android.content.Intent.ACTION_VIEW)

    openURL.data = Uri.parse(rawResult.getText())
    startActivity(openURL)

the app re-launches and goes to the activity where I set

    FirebaseDynamicLinks.getInstance()
        .getDynamicLink(intent)
        .addOnSuccessListener(this) { pendingDynamicLinkData ->
            // Get deep link from result (may be null if no link is found)
            var deepLink: Uri? = null
            if (pendingDynamicLinkData != null) {
                deepLink = pendingDynamicLinkData.link
            }

from deeplink i get custom token then i authenticate using the custom token and i get the userID

  customToken?.let {
        auth.signInWithCustomToken(it)
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {
                    // Sign in success
                    Log.d(TAG, "signInWithCustomToken:success")
                    val user = auth.currentUser

I don't want to re-launch and choose option website or app. so How can I get the dynamic link intent without launching a new activity?

1 Answers1

1

This is the solution I come up with to avoid launching new activity and disambiguation dialog:

override fun handleResult(rawResult: Result) {

    val openURL = Intent(Intent.ACTION_VIEW)
    openURL.data = Uri.parse(rawResult.text)

    FirebaseDynamicLinks.getInstance(currentfirebaseApp)
    .getDynamicLink(openURL).addOnSuccessListener {

         var deepLink: Uri? = null

         if (it != null) {
             deepLink = it.link

             val customToken = deepLink?.toString()?.substringAfter(delimiter = "*****?customToken=", missingDelimiterValue = "Token Not found")

         }

         else {
             Toast.makeText(activity!!.applicationContext,
                 "Invalid QR code",
                 Toast.LENGTH_SHORT).show()

         }

     }

}

Instead of opening the link, I only create the intent and use it with Firebase sdk.

entreprenerds
  • 957
  • 10
  • 20