加入我們的
郵寄清單,取得關於「鄰近分享」的最新消息和公告。
總覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Nearby Messages API 是一種發布/訂閱 API,可讓您在已連上網際網路的 Android 和 iOS 裝置之間傳遞小型二進位酬載。裝置不必連上相同的網路,但必須連上網際網路。
鄰近分享功能會使用低功耗藍牙技術,在裝置之間傳送專屬配對代碼。伺服器會協助偵測到相同配對碼的裝置交換訊息。當裝置偵測到鄰近裝置的配對碼時,就會將配對碼傳送至 Nearby Messages 伺服器進行驗證,並檢查應用程式目前的訂閱項目組合是否有任何訊息要傳送。
附近訊息功能不需要經過驗證,也不需要 Google 帳戶。
資料交換的確切機制可能因版本而異。以下是導致訊息交換的事件順序:
發布應用程式會提出要求,將二進位酬載 (訊息) 與唯一的時間內配對碼 (符記) 建立關聯。伺服器會在訊息酬載和權杖之間建立暫時關聯。
發布裝置會使用藍牙低功耗無線電功能,讓附近裝置偵測到權杖。發布裝置也會使用藍牙低功耗技術掃描其他裝置的符記。
訂閱應用程式會將訂閱項目與權杖建立關聯,並使用藍牙低功耗無線電功能將權杖傳送至發布者,以及偵測發布者的權杖。
當任一方偵測到另一方的符記時,就會向伺服器回報。
如果兩部裝置都與相同的符記相關聯,且呼叫應用程式使用的 API 金鑰與 Google Developers Console 中的相同專案相關聯,伺服器就會協助兩部裝置之間交換訊息。
使用 Google Play 服務 Nearby SDK 時,系統會收集使用者分析資料,以改善使用體驗。
- 成效指標:使用 Nearby SDK 時,系統會收集發布和訂閱的時間長度,以及收到的訊息數量。
- 裝置資訊:系統會收集裝置型號、國家/地區、版本和應用程式套件名稱,並與效能指標建立關聯,以識別區域和裝置專屬的切片。
- 鄰近分享訊息發布內容:透過鄰近分享訊息發布的資料會由 Google 儲存,直到訊息不再發布為止。這項資料會與裝置附近的訂閱者共用。
如要允許或拒絕這項收集行為,使用者可以前往「設定」>「Google」>「使用狀況與診斷」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eNearby Messages, a publish-subscribe API, enables the exchange of small data payloads between nearby Android and iOS devices over the internet using Bluetooth Low Energy.\u003c/p\u003e\n"],["\u003cp\u003eThis API, set to be deprecated in December 2023, is unauthenticated, doesn't require a Google account, and leverages a unique pairing code system for device discovery and message delivery.\u003c/p\u003e\n"],["\u003cp\u003eGoogle collects performance metrics, device information, and published message data to improve the service; however, users can control this data collection through their device settings.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers are encouraged to migrate to Nearby Connections for continued support and functionality.\u003c/p\u003e\n"]]],[],null,["# Overview\n\n| **Warning:** Nearby Messages is deprecated and will stop working as of December 2023. Please migrate to [Nearby Connections](//developers.google.com/nearby/connections/overview) for further support.\n\nThe Nearby Messages API is a publish-subscribe API that lets you pass small\nbinary payloads between internet-connected Android and iOS devices. The devices\ndon't have to be on the same network, but they do have to be connected to the\nInternet.\n\nNearby uses Bluetooth Low Energy to communicate a unique-in-time pairing code\nbetween devices. The server facilitates message exchange between devices that\ndetect the same pairing code. When a device detects a pairing code from a nearby\ndevice, it sends the pairing code to the Nearby Messages server for validation,\nand to check whether there are any messages to deliver for the application's\ncurrent set of subscriptions.\n\nNearby Messages is unauthenticated and does not require a Google Account.\n\nThe exact mechanism for data exchange may vary from release to release. The\nfollowing sequence shows the events leading to message exchange:\n\n1. A publishing app makes a request to associate a binary payload (the message)\n with a unique-in-time pairing code (token). The server makes a temporary\n association between the message payload and the token.\n\n2. The publishing device uses Bluetooth Low Energy to make the token detectable\n by nearby devices. The publishing device also uses Bluetooth Low Energy to scan\n for tokens from other devices.\n\n3. A subscribing app associates its subscription with a token and uses Bluetooth\n Low Energy to send its token to the publisher, and to detect the publisher's\n token.\n\n4. When either side detects the other's token, it reports it to the server.\n\n5. The server facilitates message exchange between two devices when both are\n associated with a common token, and the API keys used by the calling apps are\n associated with the same project in the [Google Developers Console](https://console.developers.google.com/).\n\nWhen using the Google Play services Nearby SDK, usage analytics are collected to\nimprove the experience.\n\n- **Performance metrics:** The duration of publishes and subscriptions and the number of messages received is collected when 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- **Nearby Messages publishes:** Data published through Nearby Messages is stored by Google until the message is no longer published. This data is shared with subscribers who are near the device.\n\nEnd users can allow or deny this collection by navigating to Settings \\\u003e Google \\\u003e\nUsage \\& diagnostics."]]