Android

The userRedirectUrl field is used to redirect the user. This field is received in the successful process creation response when making the Process Creation request. Here you will find the best way to manage the user experience, using CustomTabs, in your Android application:

Step 1: Using CustomTabs for Integration

1 - Add the necessary dependency for using CustomTabs in your app/build.gradle:

implementation("androidx.browser:browser:1.5.0")

Step 2: Opening a CustomTab

import android.net.Uri
import androidx.activity.ComponentActivity
import androidx.browser.customtabs.CustomTabsClient
import androidx.browser.customtabs.CustomTabsIntent

class CustomTabActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)

       openCustomTab(<URL_CBU>)
    }

    fun openCustomTab(url: String) {
        val builder = CustomTabsIntent.Builder()
        val customTabsIntent = builder.build()
        customTabsIntent.launchUrl(this, Uri.parse(url))
    }
}

Step 3: Modifying AndroidManifest

Add the necessary permissions and intents in the AndroidManifest.xml for the Activity that you want to receive the callback_uri. It is necessary to include the attribute android:launchMode="singleTop" as well as the <data> tag providing the URI data.

xml
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA"/> 
// ermissions for camera and geolocation are required

<activity
    android:name=".CustomTabActivity"
    android:exported="true"
    android:label="@string/app_name"
    android:theme="@style/Theme.Customtabs"
    android:launchMode="singleTop">

    <intent-filter android:label="Custom Tab">
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <!-- scheme e host são os dados fornecidos na criação de um processo no campo callback_uri
        callback_uri: "foobar://success?code=1234" -->
        <data android:scheme="foobar" android:host="success"/>
    </intent-filter>

</activity>

The following permissions are necessary for it to function correctly:

  • Camera

  • Geolocation

Step 4: Getting Return Information

o retrieve redirect information with the provided data, you can use the following code in the onNewIntent method of your Activity:

override fun onNewIntent(intent: Intent) {
    super.onNewIntent(intent)

    val url = intent.data
    val scheme = url.scheme // "foobar"
    val host = url.host // "success"
    val code = url.getQueryParameter("code") // "1234"
}

Last updated

Was this helpful?