以無線方式連結裝置
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
除了啟用雲端通訊,Android 的無線 API 也能
同一個區域網路上的其他裝置可以相互通訊
但未連上網路,但裝置就在附近。新增
Network Service Discovery (NSD) 允許應用程式
尋找附近具備能夠通訊的服務的裝置。
將這個功能整合至應用程式,可讓您
例如與同一個房間內的玩家玩遊戲、擷取
具備連網功能且具備 NSD 功能的網路攝影機,或是從遠端登入
連線至同一網路
這個類別說明可用來尋找並連結其他裝置的重要 API
應用程式。具體來說,這篇文章會說明用於探索可用服務的 NSD API,以及用於進行點對點無線連線的 Wi-Fi 點對點 (P2P) API。本課程也將說明如何結合使用 NSD 和 Wi-Fi P2P,在兩部裝置都未連上網路時,偵測裝置提供的服務,並連線至該裝置。
如果您想為 Android 應用程式尋找更高層級的 API,以便在裝置之間透過 Wi-Fi 和藍牙傳輸資料,請考慮使用 Nearby Connections API。
課程
- 使用網路服務探索功能
- 瞭解如何廣播您自己的應用程式提供的服務、探索區域網路上提供的服務,以及使用 NSD 判斷要連線的服務的連線詳細資料。
- 使用 Wi-Fi 建立 P2P 連線
- 瞭解如何擷取附近同類裝置的清單、為舊版裝置建立存取點,以及連線至其他可使用 Wi-Fi P2P 連線的裝置。
- 使用 Wi-Fi P2P 探索服務
- 瞭解如何使用 Wi-Fi P2P,在未連上相同網路的情況下,探索附近裝置發布的服務。
另請參閱
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Connect devices wirelessly\n\nBesides enabling communication with the cloud, Android's wireless APIs also\nenable communication with other devices on the same local network, and even\ndevices which are not on a network, but are physically nearby. The addition of\nNetwork Service Discovery (NSD) takes this further by allowing an application to\nseek out a nearby device running services with which it can communicate.\nIntegrating this feature into your application helps you provide a wide range of\nfeatures, such as playing games with users in the same room, pulling images from\na networked NSD-enabled webcam, or remotely logging into other machines on the\nsame network.\n\nThis class describes the key APIs for finding and connecting to other devices\nfrom your application. Specifically, it describes the NSD API for discovering\navailable services and the Wi-Fi Peer-to-Peer (P2P) API for doing peer-to-peer\nwireless connections. This class also shows you how to use NSD and Wi-Fi P2P in\ncombination to detect the services offered by a device and connect to the device\nwhen neither device is connected to a network.\n\nIf you're looking for a higher-level API for your Android application to\ntransfer data reliably and securely between devices using a combination of Wi-Fi\nand Bluetooth, consider using the [Nearby Connections API](https://developers.google.com/nearby/connections/overview). \n\nLessons\n-------\n\n**[Use network service discovery](/develop/connectivity/wifi/use-nsd)**\n: Learn how to broadcast services offered\n by your own application, discover services offered on the local network, and\n use NSD to determine the connection details for the service you want to\n connect to.\n\n**[Creating P2P connections with Wi-Fi](/develop/connectivity/wifi/wifi-direct)**\n: Learn how to fetch a list of\n nearby peer devices, create an access point for legacy devices, and connect\n to other devices capable of Wi-Fi P2P connections.\n\n**[Using Wi-Fi P2P for service discovery](/develop/connectivity/wifi/nsd-wifi-direct)**\n: Learn how to discover services\n published by nearby devices without being on the same network, using Wi-Fi\n P2P.\n\nYou should also read\n--------------------\n\n- [Wi-Fi P2P](/develop/connectivity/wifi/wifip2p)\n- [Nearby Connections API](https://developers.google.com/nearby/connections/overview)"]]