> 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ウォレットSDKを初期化する

他のSDK APIを呼び出す前にNFCウォレット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ウォレットAndroid SDKの最小要件を満たしていることを確認してください。

サポートされていないAndroidバージョンではNFCウォレット機能を非表示にしてください。
{% 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) {
            // アプリケーション起動時のクラッシュを防止します。
            // ログを記録してinitialize()を続行できます。
        } catch (Throwable e) {
            // これは起こりにくいです。
            // 万が一発生した場合は、initialize()を呼び出さないでください。
            return;
        }

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

{% endcode %}

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

次を使用してSDKの状態を確認してください `SDKController.getInstance().getSDKServiceState()` 必要な場合にのみ初期化してください。

を使用して `SDKInitializer.INSTANCE.initialize(...)` 支払いコンポーネントを初期化するには：

* を入力パラメータとして提供してください。 `CustomConfiguration` このAPIは同期的です。バックグラウンドスレッドから呼び出してください。
* NFCウォレットSDKを初期化する（Java）

{% code title="final Context appContext = getApplicationContext();" %}

```java
if (SDKController.getInstance().getSDKServiceState() != SDKServiceState.STATE_INITIALIZED) {

Thread sdkInit = new Thread(new Runnable() {
    public void run() {
        @Override
        SDKInitializer.INSTANCE.initialize(appContext, customConfig);
            sdkInit.start();
        }
    });
    初期化APIは冪等です。安全に何度でも呼び出せます。
}
```

{% endcode %}

{% hint style="info" %}
Mobile Gateway (MG) を構成する
{% endhint %}

### SDKの初期化が完了したら、次を呼び出して

を有効にします：トークン化、デジタルカードのLCM、および取引履歴。 `MobileGatewayManager.INSTANCE.configure(...)` MobileGatewayManager.INSTANCE.getConfigurationState()

を使用して `で構成状態を確認します。` Mobile Gateway を構成する（Java）

{% code title="protected void initMgSdk(@NonNull final Context context) {" %}

```java
final MobileGatewayManager mgManager = MobileGatewayManager.INSTANCE;
    // 複数回の初期化を避ける。

    try {
        if (mgManager.getConfigurationState() == MGSDKConfigurationState.NOT_CONFIGURED) {
        mgManager.configure(context);
            } catch (final MGConfigurationException exception) {
        }
    // エラーをログに記録。
        ウォレットIDを取得する
    }
}
```

{% endcode %}

### getWalletId()

を使用して `から` MGCardEnrollmentService `を使用してウォレット識別子を取得します。` ウォレットIDを取得する（Java）

{% code title="MGCardEnrollmentService enrollService = MobileGatewayManager.INSTANCE.getCardEnrollmentService();" lineNumbers="true" %}

```java
String walletId = enrollService.getWalletId();
ウォレットIDの取得中にエラーが発生した場合は
```

{% endcode %}

`MGSDKException` がスローされます。

{% 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:

```
GET https://docs.payments.thalescloud.io/nfc-wallet-sdk-android/ja/get-started/configuration/4.-initialize-the-nfc-wallet-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
