Skip to content

Most visited

Recently visited

navigation

Enable interactions between nearby devices and people

With the Nearby APIs you can let your users work or play together better when they're close, within about 100 feet: easily set up multiplayer games, ad hoc groups, sharing, or collaborative sessions.

Why it works

The unique ranging and cross-platform capabilities of Nearby make it easy to build experiences that seem magical when users are close by. This increases engagement among users who use your Nearby powered features and encourages users to share your app.

Key features

  • Messaging API: Broadcast and receive messages to enable rich interactions and collaboration among users such as multiplayer gaming, real-time collaboration, forming a group, broadcasting a resource, or sharing content.
  • Nearby Connections API: Discover other devices on the same local network and create connections for real-time cross-device experiences. With one device acting as the host, nearby devices can request to connect for collaborative whiteboards, local multiplayer gaming, or multi-screen gaming.
  • Nearby Notifications: Receive messages from beacons using Eddystone and add context to location-based apps and games. Messages can be a link to an HTTPS URL that provides a notification to the user and opens the URL in the browser when the user taps the notification. Alternatively, messages can trigger an app intent to launch an app and perform a specific action or take the user to the Play Store if the app isn't installed.

Best practices

  • Use Nearby features sparingly and only when they're needed, to preserve battery life. This is because the Nearby APIs make extensive use of radio and sensor features, consuming battery up to 3.5 times faster than normal.
  • Use an explicit action to invoke Nearby, such as a button, switch, or special screen. Provide the user with a visual indicator — for example, an animation — to show Nearby is actively sending or receiving content. Use the Nearby logo found at developers.google.com/nearby.
  • Make sure the user understands what data will be visible to nearby users of your app before they start using Nearby features.
  • Stop any publish or subscribe activity when the app doesn't need nearby or is exited. Do this by calling unpublish() and unsubscribe() in your Activity's onStop() method.
  • Limit the range of Nearby features by, using the ultrasonic modem alone by specifying Strategy.setDistanceType(DISTANCE_TYPE_EARSHOT). This restricts the range to about five feet and ensures only devices in the same room can "see" the initiator.
  • Speed up the exchange of data where one side is publishing only and the other side is subscribing only, using Strategy.setDiscoveryMode(DISCOVERY_MODE_BROADCAST) on the publishing side and DISCOVERY_MODE_SCAN on the subscribing side. Publish and subscribe are orthogonal to discovery mode (the publisher could scan and subscriber broadcast or vice versa).

Examples

Get started

Nearby
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)