Strategy

  • Strategy defines the connectivity requirements and topology constraints for discovering and advertising to nearby devices.

  • It offers three pre-defined strategies: P2P_CLUSTER, P2P_POINT_TO_POINT, and P2P_STAR, each supporting a different connection topology.

  • Each strategy requires specific platform-dependent permissions for advertising, discovering, and connecting with nearby devices, detailed in their respective sections.

  • P2P_CLUSTER is the default strategy, enabling connections within radio range where each device can initiate and accept multiple connections.

  • While P2P_POINT_TO_POINT prioritizes bandwidth with a 1-to-1 connection limit, P2P_STAR establishes a 1-to-N connection with a central hub and multiple spokes.

public final class Strategy extends Object
implements Parcelable

The Strategy to be used when discovering or advertising to Nearby devices. The Strategy defines

  1. the connectivity requirements for the device, and
  2. the topology constraints of the connection.

Inherited Constant Summary

Field Summary

public static final Strategy P2P_CLUSTER Peer-to-peer strategy that supports an M-to-N, or cluster-shaped, connection topology.
public static final Strategy P2P_POINT_TO_POINT Peer-to-peer strategy that supports a 1-to-1 connection topology.
public static final Strategy P2P_STAR Peer-to-peer strategy that supports a 1-to-N, or star-shaped, connection topology.

Public Method Summary

boolean
equals(Object object)
int
String

Inherited Method Summary

Fields

public static final Strategy P2P_CLUSTER

Peer-to-peer strategy that supports an M-to-N, or cluster-shaped, connection topology. In other words, this enables connecting amorphous clusters of devices within radio range (~100m), where each device can both initiate outgoing connections to M other devices and accept incoming connections from N other devices.

This is the default strategy, equivalent to calling the deprecated Connections API methods with no Strategy parameter.

In order to advertise with this Strategy, your app must declare the following permissions depending on your platform:

  • BLUETOOTH (Deprecated from Android S)
  • BLUETOOTH_ADMIN (Deprecated from Android S)
  • BLUETOOTH_ADVERTISE (Required for devices running S+)
  • ACCESS_WIFI_STATE
  • CHANGE_WIFI_STATE

In order to discover with this Strategy, your app must declare one of the following permissions depending on your platform:

  • ACCESS_COARSE_LOCATION (Required for devices running between M and S)
  • ACCESS_FINE_LOCATION (Required for devices running between Q and S)
  • BLUETOOTH_SCAN (Required for devices running S+)
  • NEARBY_WIFI_DEVICES (Required for devices running T+)

In order to connect with this Strategy, your app must declare the following permissions depending on your platform:

  • BLUETOOTH_CONNECT (Required for devices running S+)

public static final Strategy P2P_POINT_TO_POINT

Peer-to-peer strategy that supports a 1-to-1 connection topology. In other words, this enables connecting to a single device within radio range (~100m). This strategy will give the absolute highest bandwidth, but will not allow multiple connections at a time.

In order to advertise with this Strategy, your app must declare the following permissions depending on your platform:

  • BLUETOOTH (Deprecated from Android S)
  • BLUETOOTH_ADMIN (Deprecated from Android S)
  • BLUETOOTH_ADVERTISE (Required for devices running S+)
  • ACCESS_WIFI_STATE
  • CHANGE_WIFI_STATE

In order to discover with this Strategy, your app must declare one of the following permissions depending on your platform:

  • ACCESS_COARSE_LOCATION (Required for devices running between M and S)
  • ACCESS_FINE_LOCATION (Required for devices running between Q and S)
  • BLUETOOTH_SCAN (Required for devices running S+)
  • NEARBY_WIFI_DEVICES (Required for devices running T+)

In order to connect with this Strategy, your app must declare the following permissions depending on your platform:

  • BLUETOOTH_CONNECT (Required for devices running S+)

public static final Strategy P2P_STAR

Peer-to-peer strategy that supports a 1-to-N, or star-shaped, connection topology. In other words, this enables connecting devices within radio range (~100m) in a star shape, where each device can, at any given time, play the role of either a hub (where it can accept incoming connections from N other devices), or a spoke (where it can initiate an outgoing connection to a single hub), but not both.

This strategy lends itself best to one device who advertises itself, and N devices who discover that advertisement, though you may still advertise and discover simultaneously if required.

In order to advertise with this Strategy, your app must declare the following permissions depending on your platform:

  • BLUETOOTH (Deprecated from Android S)
  • BLUETOOTH_ADMIN (Deprecated from Android S)
  • BLUETOOTH_ADVERTISE (Required for devices running S+)
  • ACCESS_WIFI_STATE
  • CHANGE_WIFI_STATE

In order to discover with this Strategy, your app must declare one of the following permissions depending on your platform:

  • ACCESS_COARSE_LOCATION (Required for devices running between M and S)
  • ACCESS_FINE_LOCATION (Required for devices running between Q and S)
  • BLUETOOTH_SCAN (Required for devices running S+)
  • NEARBY_WIFI_DEVICES (Required for devices running T+)

In order to connect with this Strategy, your app must declare the following permissions depending on your platform:

  • BLUETOOTH_CONNECT (Required for devices running S+)

Public Methods

public boolean equals (Object object)

public int hashCode ()

public String toString ()