Android
linkフィールドはユーザーを誘導するために使用されます。このフィールドは、取引作成成功時のレスポンスで受け取ります。
ここでは、お客様のAndroidアプリケーションでユーザー体験を管理する最適な方法を紹介します。
ステップ1:連携にCustomTabsを使用する
app/build.gradleにCustomTabsを使用するために必要な依存関係を追加します。
implementation("androidx.browser:browser:1.5.0")
ステップ2: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))
}
}
ステップ3:AndroidManifestの変更
callback_uriを受け取りたいActivityのAndroidManifest.xmlに、必要な権限とインテントを追加します。属性android:launchMode="singleTop"と、URIデータを提供する<data>タグの両方を含める必要があります。
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA"/>
// カメラと位置情報の権限が必要です
<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 and host はcallback_uriフィールドで取引作成時に提供されるデータです
callback_uri: "foobar://success?code=1234" -->
<data android:scheme="foobar" android:host="success"/>
</intent-filter>
</activity>
正しく機能するためには、以下の権限が必要です。
- カメラ
- 位置情報