Strategy
Stay organized with collections
Save and categorize content based on your preferences.
The Strategy to be used when discovering or advertising to Nearby devices. The Strategy
defines
- the connectivity requirements for the device, and
- the topology constraints of the connection.
Inherited Constant Summary
From interface android.os.Parcelable
int |
CONTENTS_FILE_DESCRIPTOR |
|
int |
PARCELABLE_WRITE_RETURN_VALUE |
|
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. |
Inherited Method Summary
From class java.lang.Object
From interface android.os.Parcelable
abstract int |
describeContents
()
|
abstract void |
writeToParcel
( Parcel
arg0,
int arg1)
|
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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eStrategy\u003c/code\u003e defines the connectivity requirements and topology constraints for discovering and advertising to nearby devices.\u003c/p\u003e\n"],["\u003cp\u003eIt offers three pre-defined strategies: \u003ccode\u003eP2P_CLUSTER\u003c/code\u003e, \u003ccode\u003eP2P_POINT_TO_POINT\u003c/code\u003e, and \u003ccode\u003eP2P_STAR\u003c/code\u003e, each supporting a different connection topology.\u003c/p\u003e\n"],["\u003cp\u003eEach strategy requires specific platform-dependent permissions for advertising, discovering, and connecting with nearby devices, detailed in their respective sections.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eP2P_CLUSTER\u003c/code\u003e is the default strategy, enabling connections within radio range where each device can initiate and accept multiple connections.\u003c/p\u003e\n"],["\u003cp\u003eWhile \u003ccode\u003eP2P_POINT_TO_POINT\u003c/code\u003e prioritizes bandwidth with a 1-to-1 connection limit, \u003ccode\u003eP2P_STAR\u003c/code\u003e establishes a 1-to-N connection with a central hub and multiple spokes.\u003c/p\u003e\n"]]],["The `Strategy` class defines how devices connect and interact within proximity. It supports three peer-to-peer connection strategies: `P2P_CLUSTER` (M-to-N cluster), `P2P_POINT_TO_POINT` (1-to-1), and `P2P_STAR` (1-to-N star). Each strategy dictates the connection topology and bandwidth capabilities. To advertise, discover, or connect, apps must declare specific permissions, such as `BLUETOOTH`, `ACCESS_COARSE_LOCATION`, or `BLUETOOTH_CONNECT`, depending on the Android version. Public methods are available for checking equality, hashcode, and generating a string representation of the `Strategy` object.\n"],null,["# Strategy\n\npublic final class **Strategy** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nimplements [Parcelable](//developer.android.com/reference/android/os/Parcelable.html) \nThe Strategy to be used when discovering or advertising to Nearby devices. The Strategy\ndefines\n\n1. the connectivity requirements for the device, and\n2. the topology constraints of the connection. \n\n### Inherited Constant Summary\n\nFrom interface android.os.Parcelable \n\n|-----|-------------------------------|---|\n| int | CONTENTS_FILE_DESCRIPTOR | |\n| int | PARCELABLE_WRITE_RETURN_VALUE | |\n\n### Field Summary\n\n|------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|\n| public static final [Strategy](/android/reference/com/google/android/gms/nearby/connection/Strategy) | [P2P_CLUSTER](/android/reference/com/google/android/gms/nearby/connection/Strategy#P2P_CLUSTER) | Peer-to-peer strategy that supports an M-to-N, or cluster-shaped, connection topology. |\n| public static final [Strategy](/android/reference/com/google/android/gms/nearby/connection/Strategy) | [P2P_POINT_TO_POINT](/android/reference/com/google/android/gms/nearby/connection/Strategy#P2P_POINT_TO_POINT) | Peer-to-peer strategy that supports a 1-to-1 connection topology. |\n| public static final [Strategy](/android/reference/com/google/android/gms/nearby/connection/Strategy) | [P2P_STAR](/android/reference/com/google/android/gms/nearby/connection/Strategy#P2P_STAR) | Peer-to-peer strategy that supports a 1-to-N, or star-shaped, connection topology. |\n\n### Public Method Summary\n\n|-------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| boolean | [equals](/android/reference/com/google/android/gms/nearby/connection/Strategy#equals(java.lang.Object))([Object](//developer.android.com/reference/java/lang/Object.html) object) |\n| int | [hashCode](/android/reference/com/google/android/gms/nearby/connection/Strategy#hashCode())() |\n| [String](//developer.android.com/reference/java/lang/String.html) | [toString](/android/reference/com/google/android/gms/nearby/connection/Strategy#toString())() |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface android.os.Parcelable \n\n|---------------|--------------------------------------------------------------------------------------------------|\n| abstract int | describeContents() |\n| abstract void | writeToParcel([Parcel](//developer.android.com/reference/android/os/Parcel.html) arg0, int arg1) |\n\nFields\n------\n\n#### public static final Strategy\n**P2P_CLUSTER**\n\nPeer-to-peer strategy that supports an M-to-N, or cluster-shaped, connection\ntopology. In other words, this enables connecting amorphous clusters of devices within\nradio range (\\~100m), where each device can both initiate outgoing connections to M\nother devices and accept incoming connections from N other devices.\n\nThis is the default strategy, equivalent to calling the deprecated [Connections](/android/reference/com/google/android/gms/nearby/connection/Connections)\nAPI methods with no Strategy parameter.\n\nIn order to advertise with this Strategy, your app must declare the following\npermissions depending on your platform:\n\n- BLUETOOTH (Deprecated from Android S)\n- BLUETOOTH_ADMIN (Deprecated from Android S)\n- BLUETOOTH_ADVERTISE (Required for devices running S+)\n- ACCESS_WIFI_STATE\n- CHANGE_WIFI_STATE\n\nIn order to discover with this Strategy, your app must declare one of the following\npermissions depending on your platform:\n\n- ACCESS_COARSE_LOCATION (Required for devices running between M and S)\n- ACCESS_FINE_LOCATION (Required for devices running between Q and S)\n- BLUETOOTH_SCAN (Required for devices running S+)\n- NEARBY_WIFI_DEVICES (Required for devices running T+)\n\nIn order to connect with this Strategy, your app must declare the following\npermissions depending on your platform:\n\n- BLUETOOTH_CONNECT (Required for devices running S+) \n\n#### public static final Strategy\n**P2P_POINT_TO_POINT**\n\nPeer-to-peer strategy that supports a 1-to-1 connection topology. In other words,\nthis enables connecting to a single device within radio range (\\~100m). This strategy\nwill give the absolute highest bandwidth, but will not allow multiple connections at a\ntime.\n\nIn order to advertise with this Strategy, your app must declare the following\npermissions depending on your platform:\n\n- BLUETOOTH (Deprecated from Android S)\n- BLUETOOTH_ADMIN (Deprecated from Android S)\n- BLUETOOTH_ADVERTISE (Required for devices running S+)\n- ACCESS_WIFI_STATE\n- CHANGE_WIFI_STATE\n\nIn order to discover with this Strategy, your app must declare one of the following\npermissions depending on your platform:\n\n- ACCESS_COARSE_LOCATION (Required for devices running between M and S)\n- ACCESS_FINE_LOCATION (Required for devices running between Q and S)\n- BLUETOOTH_SCAN (Required for devices running S+)\n- NEARBY_WIFI_DEVICES (Required for devices running T+)\n\nIn order to connect with this Strategy, your app must declare the following\npermissions depending on your platform:\n\n- BLUETOOTH_CONNECT (Required for devices running S+) \n\n#### public static final Strategy\n**P2P_STAR**\n\nPeer-to-peer strategy that supports a 1-to-N, or star-shaped, connection topology.\nIn other words, this enables connecting devices within radio range (\\~100m) in a star\nshape, where each device can, at any given time, play the role of either a hub (where\nit can accept incoming connections from N other devices), or a spoke (where it can\ninitiate an outgoing connection to a single hub), but not both.\n\nThis strategy lends itself best to one device who advertises itself, and N devices\nwho discover that advertisement, though you may still advertise and discover\nsimultaneously if required.\n\nIn order to advertise with this Strategy, your app must declare the following\npermissions depending on your platform:\n\n- BLUETOOTH (Deprecated from Android S)\n- BLUETOOTH_ADMIN (Deprecated from Android S)\n- BLUETOOTH_ADVERTISE (Required for devices running S+)\n- ACCESS_WIFI_STATE\n- CHANGE_WIFI_STATE\n\nIn order to discover with this Strategy, your app must declare one of the following\npermissions depending on your platform:\n\n- ACCESS_COARSE_LOCATION (Required for devices running between M and S)\n- ACCESS_FINE_LOCATION (Required for devices running between Q and S)\n- BLUETOOTH_SCAN (Required for devices running S+)\n- NEARBY_WIFI_DEVICES (Required for devices running T+)\n\nIn order to connect with this Strategy, your app must declare the following\npermissions depending on your platform:\n\n- BLUETOOTH_CONNECT (Required for devices running S+)\n\nPublic Methods\n--------------\n\n#### public boolean **equals** ([Object](//developer.android.com/reference/java/lang/Object.html) object)\n\n#### public int **hashCode** ()\n\n#### public [String](//developer.android.com/reference/java/lang/String.html) **toString** ()"]]