> 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/help/knowledge-base/control-nfc-payments-on-android.md).

# Android で NFC 決済を制御する

## 概要

Androidのシステム設定は、あなたの **デジタルウォレットアプリケーション** が正しくても、非接触決済をブロックすることがあります。

このページでは、NFC決済に影響するAndroidのコントロールと、それらをサポートするためのアプリ側要件を説明します。

## NFC決済に影響するデバイス設定

### NFCトグル

Androidは、Wi‑Fiやモバイルデータと同様のマスターNFCスイッチを提供します。

非接触決済を実行するにはNFCを有効にする必要があります。エンドユーザーはNFCを無効にして支払いをブロックすることもできます。

<figure><img src="/files/6fecb8bcaf9df7eac88a6440cb83bb07b1a40eec" alt=""><figcaption><p>例: クイック設定のNFCトグル</p></figcaption></figure>

### デバイスのロック解除を要求（Android 12以降）

一部のデバイス（Android 12以降）では、デバイスがロック解除されている場合にのみNFCが動作するよう設定できます。

有効にされている場合、エンドユーザーはタップする前にデバイスのロックを解除する必要があります。

<figure><img src="/files/7aeb11364cf32dda03cc64b859276f350d0f39b1" alt=""><figcaption><p>例: NFCに対してロック解除を要求するオプション</p></figcaption></figure>

### アプリケーションソースの選択（OEM固有）

一部のデバイスは複数の「支払い場所」（例: セキュアエレメントとHCEなど）をサポートします。

デバイスのハードウェアは、着信NFCコマンドを選択された場所へルーティングします。

<div data-with-frame="true"><figure><img src="/files/6016db564cde5766fe11e21dd154f409d4bf0611" alt=""><figcaption><p>例: 非接触決済のアプリケーションソース選択</p></figcaption></figure></div>

{% hint style="info" %}
NFCウォレットSDKはホストベースのカードエミュレーション（HCE）を使用します。

デバイスがアプリケーションソース設定を公開している場合、エンドユーザーに次に相当するオプションを選択するよう指示してください。 **HCEウォレット**.
{% endhint %}

### デフォルトの支払いアプリケーション

Androidでは、エンドユーザーがTap & Payのデフォルト支払いアプリを選択できます。

<figure><img src="/files/bd1bd3545b88b19cdcf55e5729e8ea9920cfade1" alt=""><figcaption><p>例: デフォルト支払いアプリの設定</p></figcaption></figure>

{% hint style="info" %}
一部のデバイスは次のようなスイッチも表示します **現在開いているアプリで支払う**.

これはアプリ側のサポートが必要です。参照してください [「現在開いているアプリで支払う」をサポートする](#support-pay-with-currently-open-app).
{% endhint %}

## デジタルウォレットアプリケーションの要件（HCE）

あなたの **デジタルウォレットアプリケーション** はHCEサービスを宣言する必要があります。

NFCウォレットSDKはあなたのためにHCEサービスを宣言しません。実装を簡素化するために以下を提供します `AbstractHCEService` を提供します。

背景については、次を参照してください [ホストベースのカードエミュレーションの概要](https://developer.android.com/guide/topics/connectivity/nfc/hce).

### デフォルト支払いアプリケーションを検出および要求する

起動時には、次を行うことを推奨します:

* CardEmulation#isDefaultServiceForCategoryを使用してあなたのHCEサービスがデフォルトかどうかを確認する。 [CardEmulation#isDefaultServiceForCategory](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#isDefaultServiceForCategory\(android.content.ComponentName,%20java.lang.String\)).
* そうでない場合、CardEmulation#ACTION\_CHANGE\_DEFAULTを起動してエンドユーザーにあなたのアプリをデフォルト支払いサービスに設定するよう促します。 [CardEmulation#ACTION\_CHANGE\_DEFAULT](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#ACTION_CHANGE_DEFAULT).

```java
Intent intentSetDefaultTapNPay = new Intent();
intentSetDefaultTapNPay.setAction(ACTION_CHANGE_DEFAULT);
intentSetDefaultTapNPay.putExtra(EXTRA_SERVICE_COMPONENT, new ComponentName(this, CANONICAL_PAYMENT_SERVICENAME));
intentSetDefaultTapNPay.putExtra(EXTRA_CATEGORY, CATEGORY_PAYMENT);
startActivity(intentSetDefaultTapNPay);
```

Androidはシステムダイアログを表示します。アプリラベル以外のテキストは変更できません。

<figure><img src="/files/1a5954f33849781d4cccdf5ad6d7b8bd99875169" alt=""><figcaption><p>例: デフォルト支払いアプリを変更するAndroidダイアログ</p></figcaption></figure>

ユーザーの選択を監視するには、次を呼び出してください `startActivityForResult` そして結果を次で確認します `onActivityResult`:

```java
private void checkAndSetTapNPayDefault() {
  // ...
  startActivityForResult(intentSetDefaultTapNPay, REQ_CODE_TAP_N_PAY_SET_DEFAULT);
}

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  if (requestCode == REQ_CODE_TAP_N_PAY_SET_DEFAULT) {
    if (resultCode == RESULT_OK) {
      // ユーザーが「置き換える」を選択した
    } else {
      // ユーザーが「いいえ」を選択した
    }
  }
}
```

### Android設定でアプリの表示を制御する

Tap & Pay / 非接触決済のUIはOEM、機種、Androidバージョンによって異なります。

<figure><img src="/files/d0a26d951372fabdab459d6b0553cf185334d337" alt=""><figcaption><p>例: デバイス間のTap &#x26; Pay UIの違い</p></figcaption></figure>

Androidは次のリソースからアプリケーションエントリを構築します:

* `AndroidManifest.xml`
* あなたの支払いサービスのメタデータリソース（で宣言） `/manifest/application/service/meta-data/@android:resource`)

次を制御できます:

* **アプリケーションアイコン**: `/manifest/application/@android:icon`
* **支払いサービスバナー**：支払いサービスメタデータ、 `/host-apdu-service/@android:apduServiceBanner`
* **支払いサービスラベル**: `/manifest/application/service/@android:label`
  * このラベルは「デフォルト支払いアプリを設定」ダイアログでも使用されます。
* **支払いサービスの説明**：支払いサービスメタデータ、 `/host-apdu-service/@android:description`

リスト内のアプリの順序を制御することはできません。

### フォアグラウンドアプリで支払う

一部のデバイスは次のような設定を公開します **現在開いているアプリで支払う** または **現在実行中のアプリを優先する**.

この設定は、エンドユーザーがフォアグラウンドのアプリにデフォルト支払いサービスを上書きすることを許可するという意味にすぎません。動作を強制するものではありません。

これを活用するには、次を実装してください [CardEmulation#setPreferredService](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#setPreferredService\(android.app.Activity,%20android.content.ComponentName\)) と [CardEmulation#unsetPreferredService](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#unsetPreferredService\(android.app.Activity\)) Androidのガイドラインに従って。

{% hint style="info" %}
The `Activity` に渡される `setPreferredService(...)` は再開（resumed）状態でなければなりません。

呼び出す `setPreferredService(...)` に [Activity#onResume](https://developer.android.com/reference/android/app/Activity#onResume\(\)).

呼び出す `unsetPreferredService(...)` に [Activity#onPause](https://developer.android.com/reference/android/app/Activity#onPause\(\)).

使用する [CardEmulation#categoryAllowsForegroundPreference](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#categoryAllowsForegroundPreference\(java.lang.String\)) を使用して支払いカテゴリでフォアグラウンド優先が許可されているか検出します。
{% endhint %}

推奨事項:

* CardEmulation.categoryAllowsForegroundPreference(CATEGORY\_PAYMENT)を使用してフォアグラウンド優先が有効か確認してください。 `CardEmulation.categoryAllowsForegroundPreference(CATEGORY_PAYMENT)`.
* 前述のようにデフォルトアプリのオーバーライドを実装してください。
* デジタルウォレットアプリケーションがフォアグラウンド時にのみ非接触取引を処理する場合、支払い体験が一貫しない可能性があることをエンドユーザーに警告してください。


---

# 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/help/knowledge-base/control-nfc-payments-on-android.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.
