概要
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Nearby Connections は、ネットワーク接続に関係なく、アプリが近くのデバイスを簡単に検出して接続し、リアルタイムでデータを交換できるようにするピアツーピア ネットワーキング API です。
ユースケースの例:
- 共同作業用ホワイトボード: 近くにいる参加者と共有の仮想ホワイトボードでアイデアを書き留めます。
- ローカル マルチプレーヤー型ゲーム: マルチプレーヤー型ゲームを設定し、近くにいる他のユーザーを招待して参加してもらいます。
- マルチスクリーン ゲーム: スマートフォンやタブレットをゲーム コントローラとして使用し、Android TV などの近くにある大画面の Android デバイスに表示されるゲームをプレイします。
- オフラインでのファイル転送: ネットワーク接続を必要とせずに、写真、動画、その他の種類のデータをすばやく共有できます。
はじめに
Nearby Connections を使用すると、付近のデバイス間のアドバタイズ、検出、接続を完全にオフラインのピアツーピア方式で行うことができます。デバイス間の接続は、高速で安全なデータ転送を可能にするため、高帯域幅、低レイテンシ、完全な暗号化が施されています。
この API の主な目標は、シンプルで信頼性が高く、パフォーマンスに優れたプラットフォームを提供することです。内部では、API は Bluetooth、BLE、Wi-Fi の技術を組み合わせて使用し、それぞれの長所を活用しながら、それぞれの短所を回避します。これにより、さまざまなプラットフォームと OS バージョンにわたる Bluetooth と Wi-Fi の変動が効果的に抽象化され、デベロッパーはユーザーにとって重要な機能に集中できるようになります。
API の概要
API の使用は、接続前と接続後の 2 つのフェーズに分かれます。
接続前のフェーズでは、Advertiser は自身をアドバタイズし、Discoverer は近くの Advertiser を検出して接続リクエストを送信します。ディスカバラーからアドバタイザーへの接続リクエストにより、対称認証フローが開始され、両側で接続リクエストを個別に承認(または拒否)します。
接続リクエストが両側で承認されると、接続が確立されたと見なされ、デバイスは接続後のフェーズに入ります。このフェーズでは、両側でデータを交換できます。
広告と検出
アドバタイザーは他のディスカバーに表示され、新しいアドバタイザーが見つかった場合や消失した場合にディスカバーに通知されます。
接続を確立する
検出者が近くの広告主への接続を希望する場合、検出者は接続をリクエストできます。
接続の開始プロセスが両側に通知され、両側で接続を承認または拒否できます。
両者が回答すると、それぞれに結果が通知されます。両側が接続を承認すると、接続が確立されたと見なされ、データ転送を開始できます。
データの交換
接続が確立されると、以降の API の使用は対称的になるため、アドバタイザーとディスカバラーの区別はなくなります。
両側でデータを交換できるようになりました。サポートされているペイロードには次の 3 種類があります。
- バイト: 32k に制限されたバイト配列。メタデータや制御メッセージなどの送信に適しています。
- ファイル: サイズを問わず、アプリからネットワーク インターフェースに転送されます。プロセス境界を越えたコピーは最小限に抑えられます。
- ストリーム: 録音された音声や動画のように、最終的なサイズが事前にわからない状態で、その場で生成されるデータのストリーム。
受信側には、新しい受信データと、進捗状況の更新、キャンセル、失敗に関する通知が届きます。
確立された接続は全二重通信です。つまり、広告主と検出者は同時にデータを送受信できます。
データ収集
Google Play 開発者サービスの Nearby SDK を使用すると、ユーザー エクスペリエンスを向上させるために使用状況の分析情報が収集されます。
- パフォーマンス指標: Nearby SDK を使用してデバイスをスキャンして接続する際に、検出と接続のレイテンシ、信頼性、スループットが収集されます。
- デバイス情報: デバイスのモデル、国、ビルド バージョン、アプリのパッケージ名が収集され、パフォーマンス指標に関連付けられて、地域やデバイス固有のスライスが特定されます。
エンドユーザーは、[設定] > [Google] > [使用状況と診断情報] に移動して、この収集を許可または拒否できます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-13 UTC。
[null,null,["最終更新日 2025-08-13 UTC。"],[[["\u003cp\u003eNearby Connections is a peer-to-peer networking API enabling apps to discover, connect, and exchange data with nearby devices in real-time, even without internet access.\u003c/p\u003e\n"],["\u003cp\u003eIt leverages Bluetooth, BLE, and Wi-Fi for high-bandwidth, low-latency, and encrypted communication, abstracting away the complexities of these technologies.\u003c/p\u003e\n"],["\u003cp\u003eThe API facilitates advertising, discovery, and connection establishment between devices, followed by data exchange using bytes, files, or streams.\u003c/p\u003e\n"],["\u003cp\u003eUsage analytics, including performance metrics and device information, are collected to enhance the API's performance but can be controlled by users in their device settings.\u003c/p\u003e\n"]]],[],null,["# Overview\n\nNearby Connections is a peer-to-peer networking API that allows apps to easily\ndiscover, connect to, and exchange data with nearby devices in real-time,\nregardless of network connectivity.\n\nSome example use cases:\n\n- **Collaborative whiteboard:** Jot ideas down with nearby participants on a shared virtual whiteboard.\n- **Local multiplayer gaming:** Set up a multiplayer game and invite other users nearby to join.\n- **Multi-screen gaming:** Use a phone or tablet as a game controller to play games displayed on a nearby large-screen Android device, such as Android TV.\n- **Offline file transfers:** Share photos, videos, or any other type of data quickly and without requiring a network connection.\n\nIntroduction\n------------\n\nNearby Connections enables advertising, discovery, and connections between\nnearby devices in a fully-offline peer-to-peer manner. Connections between\ndevices are high-bandwidth, low-latency, and fully encrypted to enable fast,\nsecure data transfers.\n\nA primary goal of this API is to provide a platform that is simple, reliable,\nand performant. Under the hood, the API uses a combination of Bluetooth, BLE,\nand Wi-Fi technologies, leveraging the strengths of each while circumventing\ntheir respective weaknesses. This effectively abstracts the vagaries of\nBluetooth and Wi-Fi across a range of platforms and OS versions, allowing\ndevelopers to focus on the features that matter to their users.\n\nAPI overview\n------------\n\nUsage of the API falls into two phases: pre-connection, and post-connection.\n\nIn the pre-connection phase, Advertisers advertise themselves, while Discoverers\ndiscover nearby Advertisers and send connection requests. A connection request\nfrom a Discoverer to an Advertiser initiates a symmetric authentication flow\nthat results in both sides independently accepting (or rejecting) the connection\nrequest.\n\nAfter a connection request is accepted by both sides, the connection is\nconsidered to be established and the devices enter the post-connection phase,\nduring which both sides can exchange data.\n\n### Advertising and discovery\n\nAdvertisers will become visible to other discovers and discoverers will be\nnotified when a new advertiser is found or has been lost.\n\n### Establishing connections\n\nWhen a discoverer wishes to connect to a nearby advertiser, the discoverer can\nrequest a connection.\n\nBoth sides will be notified of the connection initiation process and both will\nhave the opportunity to accept or reject the connection.\n\nOnce both sides have responded, each will be notified of the result. If both\nsides accepted the connection, the connection is considered established, and\ndata transference can then begin.\n\n### Exchanging data\n\nAfter a connection is established, further API usage is symmetrical, so there's\nno longer a distinction between Advertiser and Discoverer.\n\nBoth sides can now exchange data. There are 3 types of supported Payloads:\n\n- **Bytes:** Byte arrays limited to 32k; these are good for sending things such as metadata or control messages.\n- **File:** Files of any size; these are transferred from the app to the network interface with minimal copying across process boundaries.\n- **Stream:** A stream of data that is generated on the fly, as in the case of recorded audio/video, with no final size known beforehand.\n\nReceivers will be notified of new incoming data and any progress updates,\ncancellations or failures.\n\nThe connections established are full-duplex, which means that advertisers and\ndiscoverers can simultaneously send and receive data.\n\n### Data Collection\n\nWhen using the Google Play services Nearby SDK, usage analytics are collected to\nimprove the experience.\n\n- **Performance metrics:** Discovery and connection latency, reliability and throughput are collected when scanning for and connecting to devices using the Nearby SDK.\n- **Device information:** Device model, country, build version and the application package name are collected and associated with the performance metrics to identify regional and device-specific slices.\n\nEnd users can allow or deny this collection by navigating to Settings \\\u003e Google \\\u003e\nUsage \\& diagnostics."]]