> 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/get-started/configuration/4.-initialize-the-nfc-wallet-sdk.md).

# 4. NFC Wallet SDKを初期化する

## NFC Wallet SDK を初期化する

他の SDK API を呼び出す前に NFC Wallet SDK を初期化してください。

推奨フロー:

1. 必要なプロパティファイルを追加します。
2. 作成する `CustomConfiguration`.
3. （任意） `SDKInitializer.INSTANCE.configure(...)` をアプリ起動時に呼び出します。
4. 呼び出します `SDKInitializer.INSTANCE.initialize(...)` をバックグラウンドスレッドで呼び出します。
5. 呼び出します `MobileGatewayManager.INSTANCE.configure(...)` を設定するために **Mobile Gateway（MG）**.

{% hint style="warning" %}

### Android バージョンを確認する

SDK を初期化する前に、Android バージョンが NFC Wallet Android SDK の最低要件を満たしていることを確認してください。

サポート対象外の Android バージョンでは NFC Wallet の機能を非表示にします。
{% endhint %}

### 必要なプロパティファイルを追加する

Android の次の **デジタルウォレットアプリケーション** `assets` フォルダーに、

* `mobilegateway.properties`
* `rages.properties`
* `gemcbp.properties`

Thales から提供された値を設定します（ただし、以下で明示的に固定値とマークされている値は除きます）。

#### mobilegateway.properties

<details>

<summary>mobilegateway.properties の説明</summary>

<table><thead><tr><th width="353">キー</th><th>説明</th></tr></thead><tbody><tr><td>MG_CONNECTION_URL</td><td>[String] MG サーバーの URL（Thales 提供）。</td></tr><tr><td>MG_TRANSACTION_HISTORY_CONNECTION_URL</td><td>[String] 取引履歴を取得するための URL（Thales 提供）。</td></tr><tr><td>WALLET_PROVIDER_ID</td><td>[String] ウォレットプロバイダー ID。</td></tr><tr><td>WALLET_APPLICATION_ID</td><td>[String] ウォレットプロバイダーのアプリケーション ID（任意）。ウォレットプロバイダーが複数のウォレットアプリケーションをサポートする場合に必要です。</td></tr><tr><td>MG_CONNECTION_TIMEOUT</td><td>[Integer] 接続タイムアウト（ミリ秒）。推奨: 30000。</td></tr><tr><td>MG_CONNECTION_READ_TIMEOUT</td><td>[Integer] 読み取りタイムアウト（ミリ秒）。推奨: 30000。</td></tr><tr><td>MG_RETRY_COUNTER</td><td>[Integer] リトライ回数。推奨: 3。</td></tr><tr><td>MG_RETRY_INTERVAL</td><td>[Integer] リトライ間隔（ミリ秒）。推奨: 10000。</td></tr></tbody></table>

</details>

#### rages.properties

<details>

<summary>rages.properties の説明</summary>

<table><thead><tr><th width="353">キー</th><th>説明</th></tr></thead><tbody><tr><td>REALM</td><td>[String] 固定値: <strong>CBP</strong>.</td></tr><tr><td>OAUTH_CONSUMER_KEY</td><td>[String] OAuth コンシューマーキー（Thales 提供）。</td></tr><tr><td>RAGES_GATEWAY_URL</td><td>[String] RAGES ゲートウェイ URL（Thales 提供）。</td></tr><tr><td>RAGES_CONNECTION_TIMEOUT</td><td>[Integer] 接続タイムアウト（ミリ秒）。推奨: 30000。</td></tr><tr><td>CSR_DOMAIN</td><td>[String] HTTPS 用の証明書署名要求（CSR）で使用するドメイン。値は Thales のデリバリーチームに問い合わせてください。</td></tr><tr><td>CSR_EMAIL</td><td>[String] 会社のメールアドレス。</td></tr></tbody></table>

</details>

#### gemcbp.properties

<details>

<summary>gemcbp.properties の説明</summary>

<table><thead><tr><th width="353">キー</th><th>説明</th></tr></thead><tbody><tr><td>CPS_URL</td><td>[String] CPS の URL（Thales 提供）。</td></tr><tr><td>CPS_CONNECTION_TIMEOUT</td><td>[Integer] 接続タイムアウト（ミリ秒）。推奨: 30000。</td></tr><tr><td>CPS_READ_TIMEOUT</td><td>[Integer] 読み取りタイムアウト（ミリ秒）。推奨: 30000。</td></tr></tbody></table>

</details>

### 支払い動作を設定する

`CustomConfiguration` は支払い動作を定義します:

* `keyValidityPeriod`: エンドユーザー認証の終了から POS 端末へのタップまでの時間（秒）。範囲: 0～300。デフォルト: 45。
* `domesticCurrencyCode`: [ISO 4217 の数値通貨コード](https://en.wikipedia.org/wiki/ISO_4217) LVT（少額取引）決済時の CDCVM に使用されます。デフォルト: 978（EUR）。

{% hint style="info" %}
`CustomConfiguration` 追加のリスク管理および CDCVM パラメーターをサポートします。参照してください [リスク管理を定義する](/nfc-wallet-sdk-android/ja/implement-nfc-wallet/make-payment/implement-contactless-payments/7.-configure-cdcvm-experiences/define-risk-management.md).

非接触決済を実装する際は、これらのパラメーターを確認することを推奨します。
{% endhint %}

SDK は `CustomConfiguration` を初期化時に使用します。

```java
/* デフォルトとは異なる値で SDK を初期化 */
CustomConfiguration customConfig = new CustomConfiguration.Builder()
                .domesticCurrencyCode(978)
                .keyValidityPeriod(60)
                .build();
```

{% hint style="warning" %}
変更しないでください `keyValidityPeriod` と `domesticCurrencyCode` 最初の初期化後は。

変更すると、認証から POS 端末での最終タップまでに遅延や断続的な問題が発生する可能性があります。
{% endhint %}

### SDK のクイック設定を実行する（任意）

使用する `SDKInitializer.INSTANCE.configure(...)` Android の `Context`, `CustomConfiguration`とネイティブライブラリを事前読み込みするために

の後、 `configure(...)` が完了すると、ローカルの SDK ストレージのみを読み取る API を呼び出せます。

参照 [SDK API の要件](/nfc-wallet-sdk-android/ja/help/sdk-api-requirements.md) を参照してください。

{% hint style="info" %}
`configure()` は SDK の移行を実行しません。移行が必要な場合は、 `initialize()`.
{% endhint %}

{% code title="MyApp.java" expandable="true" %}

```java
public class MyApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        try {
            // 1. CustomConfiguration を作成します（上記を参照）。
            ...

            // 2. SDK が Android Context を持つことを確認するためにクイック設定を実行します。
            SDKInitializer.INSTANCE.configure(this, customConfig);
        } catch (InternalComponentException e) {
            // ログを出力して initialize() を続行できます。
        } catch (Exception e) {
            // Application 起動時のクラッシュを防ぎます。
            // ログを出力して initialize() を続行できます。
        } catch (Throwable e) {
            // これは起こりにくいです。
            // もし発生した場合は initialize() を呼び出さないでください。
            return;
        }

        // 3. Application の起動がブロックされないよう、SDK を非同期で初期化します。
        // 以下の「SDK を初期化する（支払い）」を参照してください。
    }
}
```

{% endcode %}

### SDK を初期化する（支払い）

SDK の状態を `SDKController.getInstance().getSDKServiceState()` で確認し、必要な場合のみ初期化します。

使用する `SDKInitializer.INSTANCE.initialize(...)` 支払いコンポーネントを初期化するために:

* 次を指定します `CustomConfiguration` を入力パラメーターとして。
* この API は同期的です。バックグラウンドスレッドから呼び出してください。

{% code title="NFC Wallet SDK を初期化する（Java）" %}

```java
final Context appContext = getApplicationContext();

if (SDKController.getInstance().getSDKServiceState() != SDKServiceState.STATE_INITIALIZED) {
    Thread sdkInit = new Thread(new Runnable() {
        @Override
        public void run() {
            SDKInitializer.INSTANCE.initialize(appContext, customConfig);
        }
    });
    sdkInit.start();
}
```

{% endcode %}

{% hint style="info" %}
初期化 API は冪等です。複数回呼び出しても安全です。
{% endhint %}

### Mobile Gateway（MG）を設定する

SDK の初期化が完了したら、 `MobileGatewayManager.INSTANCE.configure(...)` を呼び出して、トークナイゼーション、デジタルカード LCM、および取引履歴を有効にします。

使用する `MobileGatewayManager.INSTANCE.getConfigurationState()` で設定状態を確認します。

{% code title="Mobile Gateway（Java）を設定する" %}

```java
protected void initMgSdk(@NonNull final Context context) {
    final MobileGatewayManager mgManager = MobileGatewayManager.INSTANCE;

    try {
        // 複数回の初期化を避けます。
        if (mgManager.getConfigurationState() == MGSDKConfigurationState.NOT_CONFIGURED) {
            mgManager.configure(context);
        }
    } catch (final MGConfigurationException exception) {
        // エラーをログに記録します。
    }
}
```

{% endcode %}

### ウォレット ID を取得する

使用する `getWalletId()` から `MGCardEnrollmentService` を使用してウォレット識別子を取得します。

{% code title="ウォレット ID を取得する（Java）" lineNumbers="true" %}

```java
MGCardEnrollmentService enrollService = MobileGatewayManager.INSTANCE.getCardEnrollmentService();
String walletId = enrollService.getWalletId();
```

{% endcode %}

`MGSDKException` は、ウォレット ID の取得中にエラーが発生した場合にスローされます。

{% hint style="info" %}
トラブルシューティングとサポートにはウォレット ID を使用してください。
{% endhint %}

SDK を初めて初期化すると、SDK はウォレット ID を生成します:

* ウォレット ID はアプリケーションの再起動後も変わりません。
* SDK をリセットすると、ウォレット ID は再生成されます。


---

# 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/get-started/configuration/4.-initialize-the-nfc-wallet-sdk.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.
