> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/nfc-wallet-sdk-android/ja/implement-nfc-wallet/tokenize-a-card/trigger-provisioning.md).

# プロビジョニングをトリガーする

## 概要

カードをデジタル化した後、デジタルカードをプロビジョニングするためのプロビジョニング セッションを開始します。

プロビジョニング セッション中に、 **NFC Wallet** デジタルカード プロファイルと決済キーを安全に、あなたの **デジタルウォレットアプリケーション**.

次を受け取ったらすぐにプロビジョニング セッションを開始します `activationCode` から `MGDigitizationListener.onCPSActivationCodeAcquired`。参照してください [カードをデジタル化する](/nfc-wallet-sdk-android/ja/implement-nfc-wallet/tokenize-a-card/digitize-a-card.md#sdk-integration).

このコールバックは次も返します `digitalCardId`。後続の操作（たとえば、アクセストークン、取引履歴、LCM）用に保存してください。セキュアプロビジョニングを開始するために必要ではありません。

{% hint style="info" %}
この手順では、次の間のセキュアチャネルも設定します **NFC Wallet SDK** および **NFC Wallet バックエンド**.

この設定は **デバイス登録** （別名 **CPS登録**).
{% endhint %}

## シーケンス図

<figure><img src="https://4053702943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0KuRpRJHT65Q5KFpOJb4%2Fuploads%2FvXJ6f1UnojWp32msFfdg%2FSequence%20Diagram%20-%20Trigger%20provisioning.svg?alt=media&amp;token=fd393198-a66d-49d8-9d00-7e0e8ae6ae60" alt=""><figcaption><p>セキュアプロビジョニング フロー（デバイス登録とプロビジョニング セッション）。</p></figcaption></figure>

## SDK 連携

セキュアプロビジョニングには **デバイス登録**.

デバイス登録は通常、デバイス上のウォレット インスタンスごとに1回必要です。登録が必要な場合、登録フローが自動的にプロビジョニング セッションを開始します。

デバイス登録がすでに完了している場合は、次を呼び出してプロビジョニング セッションを開始します `ProvisioningBusinessService.sendActivationCode(...)`.

SDK は `activationCode` を介して要求します `EnrollingServiceListener.onCodeRequired(...)`。その時点で値を提供してください。

### 前提条件

開始する前に、次のものがあることを確認してください:

* を初期化した **NFC Wallet SDK**。参照してください [NFC Wallet SDK を初期化する](/nfc-wallet-sdk-android/ja/get-started/configuration/4.-initialize-the-nfc-wallet-sdk.md).
* プッシュ通知を設定し、プッシュトークンを取得した。参照 [プッシュ通知](https://gitlab.sre.ops.gcloud.thalescloud.io/bps/gitbook/nfc-wallet-gitbook-docs/-/blob/dev-sdk/NFC-Wallet-SDK-Android/get-started/configuration/5.-push-notifications).
* 次を受け取った `activationCode` デジタル化から。参照先: [カードをデジタル化する](/nfc-wallet-sdk-android/ja/implement-nfc-wallet/tokenize-a-card/digitize-a-card.md#sdk-integration).

### デバイス登録

デバイス登録には、次の入力が必要です:

* `activationCode` (`byte[]`): デジタル化によって返されます。
* `walletId`: 次を使用して取得します `MGCardEnrollmentService.getWalletId()`。この値を次の `userId` パラメータとして `EnrollingBusinessService.enroll(...)`。参照してください [ウォレット ID を取得する](/nfc-wallet-sdk-android/ja/get-started/configuration/4.-initialize-the-nfc-wallet-sdk.md#retrieving-the-wallet-id).
* `pushToken`: 次のためのプッシュ トークン **FCM** または **HMS Push Kit**.

{% hint style="warning" %}
プレフィックス **HMS Push Kit** トークンに `HMS:` (たとえば、 `HMS:<token>`).
{% endhint %}

### デバイス登録ステータスを確認する

次を使用してデバイス登録ステータスを確認します `EnrollingBusinessService.isEnrolled()`.

このステータスは、このデバイス上の現在のウォレット インスタンスに対してセキュアチャネルがすでに確立されているかどうかを示します。

これは `EnrollmentStatus`:

* `ENROLLMENT_NEEDED`: 次を呼び出します `EnrollingBusinessService.enroll(...)`.
* `ENROLLMENT_IN_PROGRESS`: 次を呼び出します `EnrollingBusinessService.continueEnrollment(...)`.
* `ENROLLMENT_COMPLETE`: 次を呼び出します `ProvisioningBusinessService.sendActivationCode(...)`.

### 実装する `EnrollingServiceListener`

実装する `EnrollingServiceListener` を使って登録フローを進めます:

* `onCodeRequired`: 次を提供します `activationCode`.
* `onComplete`: デバイス登録は正常に完了します。
* `onError`: 次を使用してエラーを処理します `ProvisioningServiceError`.

<pre class="language-java" data-title="MyEnrollingServiceListener.java"><code class="lang-java"><strong>public class MyEnrollingServiceListener implements EnrollingServiceListener {
</strong>
    // MGDigitizationListener.onCPSActivationCodeAcquired(...) から受け取る
    private final byte[] activationCode;

    public MyEnrollingServiceListener(final byte[] activationCode) {
        this.activationCode = activationCode;
    }

    @Override
    public void onStarted() {
        // 登録フローが開始されたときに呼び出されます。
    }

    @Override
    public void onCodeRequired(final CHCodeVerifier chCodeVerifier) {
        // フローを続行するためにアクティベーションコードが必要なときに呼び出されます。
        final SecureCodeInputer inputer = chCodeVerifier.getSecureCodeInputer();
        for (final byte b : activationCode) {
            inputer.input(b);
        }
        inputer.finish();
    }

    @Override
    public void onComplete() {
        // デバイス登録が正常に完了すると1回呼び出されます。
        // Green フローでは、通常これはプロビジョニングが完了したことを意味します。
    }

    @Override
    public void onError(final ProvisioningServiceError error) {
        // デバイス登録が失敗したときに呼び出されます。
        // error.getCode() を解析し、適切な再試行／復旧ロジックを適用します。
    }
}
</code></pre>

### デバイス登録コードの実装

```java
byte[] activationCode = ...; // MGDigitizationListener.onCPSActivationCodeAcquired(...) から
String pushToken = "..."; // FCM または HMS Push Kit から
String language = "en"; // 可能であればアプリのロケールを使用してください。

// Wallet ID はデバイス登録のユーザー識別子です。
String walletId = MobileGatewayManager.INSTANCE.getCardEnrollmentService().getWalletId();

EnrollingServiceListener enrollingListener = new MyEnrollingServiceListener(activationCode);

final EnrollingBusinessService enrollingService = ProvisioningServiceManager.getEnrollingBusinessService();
final ProvisioningBusinessService provisioningBusinessService = ProvisioningServiceManager.getProvisioningBusinessService();

// 登録ステータスを確認します。
final EnrollmentStatus status = enrollingService.isEnrolled();
switch (status) {
    case ENROLLMENT_NEEDED:
        // このウォレット インスタンスでの最初のデバイス登録試行。
        enrollingService.enroll(walletId, pushToken, language, enrollingListener);
        break;
    
    case ENROLLMENT_IN_PROGRESS:
        // 登録は以前に開始されており、再開する必要があります。
        enrollingService.continueEnrollment(language, enrollingListener);
        break;
    
    case ENROLLMENT_COMPLETE:
        // デバイス登録はすでに完了しています。
        // このカードのプロビジョニングを開始します。
        // SDK は enrollingListener.onCodeRequired(...) を介してアクティベーションコードを要求します。
        provisioningBusinessService.sendActivationCode(enrollingListener);
        break;
    
    default:
        // エラーをログに記録します（不明なステータス）。
 }

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/nfc-wallet-sdk-android/ja/implement-nfc-wallet/tokenize-a-card/trigger-provisioning.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
