Bluetooth の概要
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android プラットフォームは Bluetooth ネットワーク スタックをサポートしています。これにより、デバイスは他の Bluetooth デバイスとワイヤレスでデータを交換できます。アプリのフレームワークでは、Bluetooth API を介して Bluetooth 機能にアクセスできます。これらの API を使用すると、アプリは他の Bluetooth デバイスに接続でき、ポイントツーポイントやマルチポイントのワイヤレス機能が有効になります。
Bluetooth API を使用すると、アプリは次のことができます。
- 他の Bluetooth デバイスをスキャンします。
- ローカルの Bluetooth アダプターに対して、ペア設定された Bluetooth デバイスのクエリを行います。
- RFCOMM チャネルを確立する。
- サービス ディスカバリを使用して他のデバイスに接続する。
- 他のデバイスとの間でデータを転送できます。
- 複数の接続を管理する。
このトピックでは、従来の Bluetooth を中心に説明します。デバイス間のストリーミングや通信など、バッテリー消費量の多い操作には、クラシック Bluetooth が適しています。低消費電力の要件がある Bluetooth デバイスでは、Bluetooth Low Energy 接続の使用を検討してください。
このドキュメントでは、さまざまな Bluetooth プロファイルについて説明し、Bluetooth API を使用して Bluetooth で通信するために必要な次の 4 つの主要タスクを実行する方法について説明します。
- Bluetooth をセットアップしています。
- ペア設定されているデバイス、またはお住まいの地域で利用可能なデバイスを探す。
- デバイスを接続しています。
- デバイス間でのデータ転送
Bluetooth API の使用方法を示すデモについては、Bluetooth Chat サンプルアプリをご覧ください。
基本情報
Bluetooth 対応デバイスが相互にデータを送信するには、まずペア設定プロセスを使用して通信チャネルを形成する必要があります。1 つのデバイス(検出可能なデバイス)は、受信接続リクエストに対して自身を使用可能にします。別のデバイスが、サービス ディスカバリ プロセスを使用して検出可能なデバイスを検出します。検出可能なデバイスがペア設定リクエストを受け入れると、2 つのデバイスはセキュリティ キーを交換するボンディング プロセスを完了します。デバイスは、後で使用するためにこれらのキーをキャッシュに保存します。ペア設定とボンディングのプロセスが完了すると、2 つのデバイスは情報を交換します。セッションが完了すると、ペア設定リクエストを開始したデバイスが、検出可能なデバイスにリンクしていたチャンネルを解放します。ただし、2 つのデバイスはボンディングされたままになるため、今後のセッション中に自動的に再接続できます。ただし、これらのデバイスが互いに接続範囲内にあり、どちらのデバイスもボンディングを解除していない場合に限ります。
Bluetooth API を使用するには、マニフェスト ファイルで複数の権限を宣言する必要があります。アプリに Bluetooth を使用する権限が付与されたら、アプリは BluetoothAdapter
にアクセスして、デバイスで Bluetooth が使用可能かどうかを判断する必要があります。Bluetooth を利用できる場合、接続を確立するには次の 3 つの手順を行います。
一部のデバイスでは、提供するデータを宣言する特定の Bluetooth プロファイルが使用されます。
キークラスとインターフェース
すべての Bluetooth API は、android.bluetooth
パッケージに含まれています。Bluetooth 接続の作成に必要なクラスとインターフェースは次のとおりです。
BluetoothAdapter
- ローカル Bluetooth アダプター(Bluetooth 無線通信)を表します。
BluetoothAdapter
は、すべての Bluetooth インタラクションのエントリ ポイントです。これを使用して、他の Bluetooth デバイスの検出、ボンディング(ペア設定)デバイスのリストをクエリ、既知の MAC アドレスを使用して BluetoothDevice
のインスタンス化、他のデバイスからの通信をリッスンする BluetoothServerSocket
の作成を行うことができます。
BluetoothDevice
- リモートの Bluetooth デバイスを表します。これを使用して、
BluetoothSocket
を介したリモート デバイスとの接続や、デバイスに関する情報(名前、アドレス、クラス、ボンディング状態など)をクエリします。 BluetoothSocket
- Bluetooth ソケットのインターフェースを表します(TCP
Socket
に類似)。この接続ポイントにより、アプリは InputStream
と OutputStream
を使用して別の Bluetooth デバイスとデータを交換できます。
BluetoothServerSocket
- 受信リクエストをリッスンするオープンなサーバー ソケットを表します(TCP
ServerSocket
と同様)。2 つのデバイスを接続するには、1 つのデバイスがこのクラスでサーバー ソケットを開く必要があります。リモート Bluetooth デバイスがこのデバイスに接続リクエストを行うと、デバイスは接続を受け入れ、接続された BluetoothSocket
を返します。
BluetoothClass
- Bluetooth デバイスの一般的な特性と機能について説明します。
デバイスのクラスとサービスを定義する読み取り専用のプロパティ セットです。この情報はデバイスの種類に関する有用なヒントを提供しますが、このクラスの属性は、必ずしもデバイスがサポートするすべての Bluetooth プロファイルとサービスを記述するわけではありません。
BluetoothProfile
- Bluetooth プロファイルを表すインターフェース。Bluetooth プロファイルは、デバイス間で Bluetooth ベースの通信を行うためのワイヤレス インターフェース仕様です。その一例が、ハンズフリー プロファイルです。プロファイルについて詳しくは、Bluetooth プロファイルをご覧ください。
BluetoothHeadset
- スマートフォンで使用する Bluetooth ヘッドセットをサポートします。これには、Bluetooth ヘッドセット プロファイルと Hands-Free(v1.5)プロファイルの両方が含まれます。
BluetoothA2dp
- Advanced Audio Distribution Profile(A2DP)を使用して、Bluetooth 接続でデバイス間で高品質の音声をストリーミングする方法を定義します。
BluetoothHealth
- Bluetooth サービスを制御する Health Device Profile プロキシを表します。
BluetoothHealthCallback
BluetoothHealth
コールバックの実装に使用する抽象クラス。このクラスを拡張し、アプリの登録状態と Bluetooth チャンネル状態の変化に関する最新情報を受け取るコールバック メソッドを実装する必要があります。
BluetoothHealthAppConfiguration
- Bluetooth Health のサードパーティ アプリがリモート Bluetooth Health デバイスと通信するために登録するアプリ構成を表します。
BluetoothProfile.ServiceListener
BluetoothProfile
のプロセス間通信(IPC)クライアントに対して、特定のプロファイルを実行する内部サービスとの接続や接続の切断を通知するインターフェース。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[],[],null,["# Bluetooth overview\n\nThe Android platform includes support for the Bluetooth network stack, which\nallows a device to wirelessly exchange data with other Bluetooth devices. The\napp framework provides access to the Bluetooth functionality through Bluetooth\nAPIs. These APIs let apps connect to other Bluetooth devices, enabling\npoint-to-point and multipoint wireless features.\n\nUsing the Bluetooth APIs, an app can perform the following:\n\n- Scan for other Bluetooth devices.\n- Query the local Bluetooth adapter for paired Bluetooth devices.\n- Establish RFCOMM channels.\n- Connect to other devices through service discovery.\n- Transfer data to and from other devices.\n- Manage multiple connections.\n\nThis topic focuses on *Classic Bluetooth* . Classic Bluetooth is the right choice\nfor more battery-intensive operations, which include streaming and communicating\nbetween devices. For Bluetooth devices with low power requirements, consider\nusing [Bluetooth Low Energy](/develop/connectivity/bluetooth/ble-overview)\nconnections.\n\nThis documentation describes different Bluetooth\n[profiles](/develop/connectivity/bluetooth/profiles) and explains how to\nuse the Bluetooth APIs to accomplish the four major tasks necessary to\ncommunicate using Bluetooth:\n\n- Setting up Bluetooth.\n- Finding devices that are either paired or available in the local area.\n- Connecting devices.\n- Transferring data between devices.\n\nFor a demonstration of using the Bluetooth APIs, see the [Bluetooth Chat sample\napp](https://github.com/android/connectivity-samples/tree/master/BluetoothChat).\n\nThe basics\n----------\n\nFor Bluetooth-enabled devices to transmit data between each other, they must\nfirst form a channel of communication using a pairing process. One device, a\ndiscoverable device, makes itself available for incoming connection requests.\nAnother device finds the discoverable device using a service discovery process.\nAfter the discoverable device accepts the pairing request, the two devices\ncomplete a bonding process in which they exchange security keys. The devices\ncache these keys for later use. After the pairing and bonding processes are\ncomplete, the two devices exchange information. When the session is complete,\nthe device that initiated the pairing request releases the channel that had\nlinked it to the discoverable device. The two devices remain bonded, however, so\nthey can reconnect automatically during a future session as long as they're in\nrange of each other and neither device has removed the bond.\n\nUse of the Bluetooth APIs requires\n[declaring several permissions](/develop/connectivity/bluetooth/bt-permissions#declare)\nin your manifest file. Once your app has permission to use Bluetooth, your app\nneeds to access the\n[`BluetoothAdapter`](/reference/android/bluetooth/BluetoothAdapter) and\n[determine if Bluetooth is available on the device](/develop/connectivity/bluetooth/setup).\nIf Bluetooth is available, there are three steps to make a connection:\n\n- [Find nearby Bluetooth\n devices](/develop/connectivity/bluetooth/find-bluetooth-devices), either devices that are already paired or new ones.\n- [Connect to a Bluetooth\n device](/develop/connectivity/bluetooth/connect-bluetooth-devices).\n- [Transfer data with the connected\n device](/develop/connectivity/bluetooth/transfer-data).\n\nCertain devices use a specific [Bluetooth\nprofile](/develop/connectivity/bluetooth/profiles) that declares the data\nit provides.\n\nKey classes and interfaces\n--------------------------\n\nAll of the Bluetooth APIs are available in the\n[`android.bluetooth`](/reference/android/bluetooth/package-summary) package.\nThe following are the classes and interfaces you need in order to create\nBluetooth connections:\n\n[`BluetoothAdapter`](/reference/android/bluetooth/BluetoothAdapter)\n: Represents the local Bluetooth adapter (Bluetooth radio). The\n `BluetoothAdapter` is the entry-point for all Bluetooth interaction. Using\n this, you can discover other Bluetooth devices, query a list of bonded\n (paired) devices, instantiate a\n `BluetoothDevice` using a known MAC address, and create a\n `BluetoothServerSocket` to listen for communications from other devices.\n\n[`BluetoothDevice`](/reference/android/bluetooth/BluetoothDevice)\n: Represents a remote Bluetooth device. Use this to request a connection with a\n remote device through a `BluetoothSocket` or query information about the\n device such as its name, address, class, and bonding state.\n\n[`BluetoothSocket`](/reference/android/bluetooth/BluetoothSocket)\n: Represents the interface for a Bluetooth socket (similar to a TCP\n [`Socket`](/reference/java/net/Socket)). This is the connection point that\n allows an app to exchange data with another Bluetooth device using\n [`InputStream`](/reference/java/io/InputStream) and\n [`OutputStream`](/reference/java/io/OutputStream).\n\n[`BluetoothServerSocket`](/reference/android/bluetooth/BluetoothServerSocket)\n: Represents an open server socket that listens for incoming requests (similar\n to a TCP [`ServerSocket`](/reference/java/net/ServerSocket)). In order to\n connect two devices, one device must open a server socket with this\n class. When a remote Bluetooth device makes a connection request to this\n device, the device accepts the connection and then returns a connected\n `BluetoothSocket`.\n\n[`BluetoothClass`](/reference/android/bluetooth/BluetoothClass)\n: Describes the general characteristics and capabilities of a Bluetooth device.\n This is a read-only set of properties that defines the device's classes and\n services. Although this information provides a useful hint regarding a\n device's type, the attributes of this class don't necessarily describe all\n Bluetooth profiles and services that the device supports.\n\n[`BluetoothProfile`](/reference/android/bluetooth/BluetoothProfile)\n: An interface that represents a Bluetooth profile. A Bluetooth profile is a\n wireless interface specification for Bluetooth-based communication between\n devices. An example is the Hands-Free profile. For more discussion of\n profiles, see [Bluetooth profiles](/develop/connectivity/bluetooth/profiles).\n\n[`BluetoothHeadset`](/reference/android/bluetooth/BluetoothHeadset)\n: Provides support for Bluetooth headsets to be used with mobile phones. This\n includes both the Bluetooth Headset profile and the Hands-Free (v1.5) profile.\n\n[`BluetoothA2dp`](/reference/android/bluetooth/BluetoothA2dp)\n: Defines how high-quality audio can be streamed from one device to another over\n a Bluetooth connection using the Advanced Audio Distribution Profile (A2DP).\n\n[`BluetoothHealth`](/reference/android/bluetooth/BluetoothHealth)\n: Represents a Health Device Profile proxy that controls the Bluetooth service.\n\n[`BluetoothHealthCallback`](/reference/android/bluetooth/BluetoothHealthCallback)\n: An abstract class that you use to implement `BluetoothHealth` callbacks. You\n must extend this class and implement the callback methods to receive updates\n about changes in the app's registration state and Bluetooth channel\n state.\n\n[`BluetoothHealthAppConfiguration`](/reference/android/bluetooth/BluetoothHealthAppConfiguration)\n: Represents an app configuration that the Bluetooth Health third-party\n app registers to communicate with a remote Bluetooth health device.\n\n[`BluetoothProfile.ServiceListener`](/reference/android/bluetooth/BluetoothProfile.ServiceListener)\n: An interface that notifies `BluetoothProfile` interprocess communication (IPC)\n clients when they have been connected to or disconnected from the internal\n service that runs a particular profile."]]