---
title: Android
description: 通过 CustomTabs 在 Android 中管理无卡验证捕获体验：依赖项、打开标签页、清单（Manifest）配置以及读取回调。
canonical: https://developer.unico.io/zh-CN/dual-api/developers/regional-solutions/card-not-present-verification/integration/controlling-the-experience/mobile/android
locale: zh-CN
generated_by: markdown-export
---

**link** 字段用于引导用户。该字段将在交易创建成功的响应中返回。

在此，您将找到在 Android 应用程序中管理用户体验的最佳方式：

### 第一步：使用 CustomTabs 进行集成

在您的 `app/build.gradle` 中添加使用 CustomTabs 所需的依赖项：

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

### 第二步：打开 CustomTab

```java
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))
    }
}
```

### 第三步：修改 AndroidManifest

请在 `AndroidManifest.xml` 中为需要接收 `callback_uri` 的 Activity 添加必要的权限和 intent。需要包含属性 `android:launchMode="singleTop"`，以及提供 URI 数据的 `<data>` 标签。

```java
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA"/>
// permissions 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 和 host 是在流程创建时通过 callback_uri 字段提供的数据
        callback_uri: "foobar://success?code=1234" -->
        <data android:scheme="foobar" android:host="success"/>
    </intent-filter>

</activity>
```

以下权限是使其正常运行所必需的：

- 摄像头
- 地理位置

### 第四步：获取返回信息

要使用提供的数据获取重定向信息，您可以在 Activity 的 `onNewIntent` 方法中使用以下代码：

```java
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"
}
```

:::tip
也可以在混合框架（hybrid frameworks）中使用 Unico 生成的链接。为此，您可以在所使用的框架与原生环境之间创建桥接（bridge），并按照我们在文档中建议的方式进行操作，或使用能够提供这些集成选项的库。
:::

:::warning
在您的应用程序中集成 WebView 完全由客户自行负责，因为该功能并非 Unico 库或 SDK 的一部分。因此，我们不针对在您的应用程序中实现 WebView 相关的问题提供技术支持。有关配置指导，我们建议您查阅项目中所使用技术的官方文档（例如 React Native、Flutter 等）。
:::