Nearby Connections for Android: Getting Started

Learn how to exchange data between two Android devices in an offline peer-to-peer fashion using the Nearby Connections API By Fernando Sproviero.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 3 of 3 of this article. Click here to view the first page.

Where to Go From Here?

You can download the final version of the project using the Download Materials button at the top or bottom of this tutorial.

As a challenge, you can let more players connect to the host and use a bigger board, the TicTacToe model already allows that. Here are a few tips that will help you:

  • You’ll need to choose another connection strategy.
  • Let the host decide the board size.
  • Because the host doesn’t know how many opponents will connect beforehand, you’ll need to set the local and opponent player numbers when the game starts.
  • Instead of immediately starting the game whenever an opponent joins, wait for more than one to join and let the host decide when to start.
  • You’ll need a new payload to signal to all the opponents that the host has started a new game.

You can find the solution in the materials.

Here are some great references to learn more about the subject:

  • You can find the official documentation here.
  • Here you’ll find the API reference.
  • If you liked this, you might want to build a ‘rock, paper and scissors’ multiplayer game, just follow along this codelab.
  • For other Nearby use cases, check this blog series.

Feel free to share your feedback and findings or ask any questions in the comments below or in the forums. We hope you enjoyed this tutorial!