> 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="https://4053702943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0KuRpRJHT65Q5KFpOJb4%2Fuploads%2FEK9WbO7AMppt28s7G4P1%2Fimage.png?alt=media&amp;token=07aaacd9-041d-463f-b8b9-3fca6ed19bbd" alt=""><figcaption><p>例: クイック設定の NFC 切り替え</p></figcaption></figure>

### デバイスのロック解除を必須にする（Android 12+）

一部のデバイス（Android 12+）では、デバイスのロックが解除されているときのみ NFC が機能するように設定できます。

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

<figure><img src="https://4053702943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0KuRpRJHT65Q5KFpOJb4%2Fuploads%2FFBMqKHNVlDrBWSD28r42%2Fimage.png?alt=media&amp;token=e6bcfcfe-bd19-4a79-b228-84d7a48c06d6" alt=""><figcaption><p>例: NFC に対してロック解除済みデバイスを必須にするオプション</p></figcaption></figure>

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

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

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

<div data-with-frame="true"><figure><img src="https://4053702943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0KuRpRJHT65Q5KFpOJb4%2Fuploads%2FoJIGAL6veGqKs7jrL07q%2Fimage.png?alt=media&amp;token=0f8aceeb-a479-48fd-9afe-aec77d5c287c" alt=""><figcaption><p>例: 非接触決済用のアプリケーション ソース選択</p></figcaption></figure></div>

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

デバイスでアプリケーション ソース設定が表示される場合は、次に相当するオプションを選択するようエンドユーザーに案内してください **HCE Wallet**.
{% endhint %}

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

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

<figure><img src="https://4053702943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0KuRpRJHT65Q5KFpOJb4%2Fuploads%2FrRq0I1RHjz2VZtxmzI1m%2Fimage.png?alt=media&amp;token=a36baef3-0394-479b-b00b-edc954f0b6e6" alt=""><figcaption><p>例: デフォルトの支払いアプリケーション設定</p></figcaption></figure>

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

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

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

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

NFC Wallet SDK は HCE サービスを自動では宣言しません。代わりに次を提供します `AbstractHCEService` 実装を簡素化するためのものです。

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

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

起動時には、次を推奨します:

* 次を使用して、あなたの HCE サービスがデフォルトかどうかを確認する [CardEmulation#isDefaultServiceForCategory](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#isDefaultServiceForCategory\(android.content.ComponentName,%20java.lang.String\)).
* そうでない場合は、次を起動して、アプリをデフォルトの支払いサービスとして設定するようエンドユーザーに促します [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="https://4053702943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0KuRpRJHT65Q5KFpOJb4%2Fuploads%2Fy3nvNQRB7LRwGtwe3MsP%2Fimage.png?alt=media&amp;token=e6035e17-4976-40c7-89f2-47cf930e6c22" 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) {
      // ユーザーが 'Replace' を選択
    } else {
      // ユーザーが 'No' を選択
    }
  }
}
```

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

Tap & Pay / Contactless payments の UI は、OEM、モデル、Android のバージョンによって異なります。

<figure><img src="https://4053702943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0KuRpRJHT65Q5KFpOJb4%2Fuploads%2FY8iAcmCe4YBouv5r5JwE%2Fimage.png?alt=media&amp;token=887ebf20-d10b-41d9-8382-fff966b7eff0" 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" %}
その `Activity` に渡される `setPreferredService(...)` は再開状態である必要があります。

呼び出します `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)`.
* 前述のとおり、デフォルト アプリケーションの上書きを実装してください。
* デジタルウォレット アプリケーションがフォアグラウンドにあるときにのみ非接触取引を処理する場合は、支払い体験が一貫しない可能性があることをエンドユーザーに警告してください。


---

# 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.
