无线连接设备
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 的无线 API 除了支持与云通信,还支持与同一本地网络上的其他设备通信,甚至包括不在网络上但物理上紧邻的设备。添加网络服务发现 (NSD) 进一步增强了这一功能,它允许应用查找附近运行服务的设备,以便与之通信。将此功能集成到您的应用中,可帮助您提供广泛的功能,比如和在同一房间中的用户一起玩游戏,从支持 NSD 的网络摄像头中提取图片,或远程登录到同一网络中的其他计算机。
本课介绍了用于查找和连接到其他设备的关键 API
。具体来说,它介绍了 NSD API,用于发现
以及用于进行点对点连接的 Wi-Fi 点对点 (P2P) API
无线连接。本课程还介绍了如何在
用于检测设备提供的服务并连接到该设备
当两个设备都没有连接到网络时。
如果您正在为 Android 应用寻找更高级别的 API,以便结合使用 WLAN 和蓝牙在设备之间安全可靠地传输数据,那么可以考虑使用 Nearby Connections API。
课程
- 使用网络服务发现
- 了解如何广播您的应用提供的服务,发现本地网络上提供的服务,以及使用 NSD 确定您要连接到的服务的连接细节。
- 通过 WLAN 建立点对点连接
- 了解如何获取附近对等设备的列表,为旧版设备创建接入点,以及连接到其他支持 WLAN 点对点连接的设备。
- 将 WLAN 点对点用于服务发现
- 了解如何发现服务
由附近设备发布,而未连接到同一网络且使用 Wi-Fi
P2P。
另请阅读
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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)"]]