Strategy.Builder
Stay organized with collections
Save and categorize content based on your preferences.
Public Constructor Summary
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Public Methods
public Strategy.Builder
setDiscoveryMode (int
discoveryMode)
Sets the desired discovery mode that determines how devices will detect each
other.
The discovery mode is orthogonal to if device is publishing or subscribing for
messages. It's just the mechanism for detecting nearby devices. By default, the devices
will broadcast and scan for pairing codes, so other devices can detect the originator
from either a scan or a broadcast as well or both. Doing both allows for inclusion of
devices that can only broadcast.
Parameters
discoveryMode |
One of Strategy.DISCOVERY_MODE_* specifying how to detect nearby
devices. |
public Strategy.Builder
setDistanceType (int
distanceType)
If used with a publish, the published message will only be delivered to subscribing
devices that are at most the specified distance from this device.
If used with a subscribe, messages will only be delivered if the publishing device
is at most the specified distance from this device.
Parameters
distanceType |
One of Strategy.DISTANCE_TYPE_* specifying how close nearby
devices must be. |
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.
[null,null,["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eStrategy.Builder\u003c/code\u003e is used to create \u003ccode\u003eStrategy\u003c/code\u003e objects, which define how devices discover each other and exchange messages in Nearby Messages.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize discovery modes, distance thresholds, and message time-to-live (TTL) using builder methods like \u003ccode\u003esetDiscoveryMode\u003c/code\u003e, \u003ccode\u003esetDistanceType\u003c/code\u003e, and \u003ccode\u003esetTtlSeconds\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCalling \u003ccode\u003ebuild()\u003c/code\u003e on a \u003ccode\u003eStrategy.Builder\u003c/code\u003e instance returns a configured \u003ccode\u003eStrategy\u003c/code\u003e object ready for use with Nearby Messages API.\u003c/p\u003e\n"],["\u003cp\u003eThe builder initializes with default settings equivalent to \u003ccode\u003eStrategy.DEFAULT\u003c/code\u003e for convenience.\u003c/p\u003e\n"]]],["The `Strategy.Builder` class facilitates the creation of `Strategy` instances. Key actions include creating a new `Builder` with default settings, building a `Strategy` instance, setting the discovery mode to define how devices detect each other, setting the distance type to specify proximity requirements for message delivery, and setting the time-to-live (TTL) in seconds for publish or subscribe actions. TTL can be set to infinite or a value between 1 and the maximum limit.\n"],null,["# Strategy.Builder\n\npublic static class **Strategy.Builder** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nBuilder for [Strategy](/android/reference/com/google/android/gms/nearby/messages/Strategy). \n\n### Public Constructor Summary\n\n|---|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder#Builder())() Creates a new [Strategy.Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder). |\n\n### Public Method Summary\n\n|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Strategy](/android/reference/com/google/android/gms/nearby/messages/Strategy) | [build](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder#build())() Builds an instance of [Strategy](/android/reference/com/google/android/gms/nearby/messages/Strategy). |\n| [Strategy.Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder) | [setDiscoveryMode](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder#setDiscoveryMode(int))(int discoveryMode) Sets the desired discovery mode that determines how devices will detect each other. |\n| [Strategy.Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder) | [setDistanceType](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder#setDistanceType(int))(int distanceType) If used with a publish, the published message will only be delivered to subscribing devices that are at most the specified distance from this device. |\n| [Strategy.Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder) | [setTtlSeconds](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder#setTtlSeconds(int))(int ttlSeconds) Sets the time to live in seconds for the publish or subscribe. |\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\nPublic Constructors\n-------------------\n\n#### public **Builder** ()\n\nCreates a new [Strategy.Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder).\nBy default it will have the same settings as a [Strategy.DEFAULT](/android/reference/com/google/android/gms/nearby/messages/Strategy#DEFAULT)\nstrategy.\n\nPublic Methods\n--------------\n\n#### public [Strategy](/android/reference/com/google/android/gms/nearby/messages/Strategy)\n**build** ()\n\nBuilds an instance of [Strategy](/android/reference/com/google/android/gms/nearby/messages/Strategy). \n\n#### public [Strategy.Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder)\n**setDiscoveryMode** (int discoveryMode)\n\nSets the desired discovery mode that determines how devices will detect each\nother.\n\nThe discovery mode is orthogonal to if device is publishing or subscribing for\nmessages. It's just the mechanism for detecting nearby devices. By default, the devices\nwill broadcast and scan for pairing codes, so other devices can detect the originator\nfrom either a scan or a broadcast as well or both. Doing both allows for inclusion of\ndevices that can only broadcast. \n\n##### Parameters\n\n| discoveryMode | One of `Strategy.DISCOVERY_MODE_*` specifying how to detect nearby devices. |\n|---------------|-----------------------------------------------------------------------------|\n\n#### public [Strategy.Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder)\n**setDistanceType** (int distanceType)\n\nIf used with a publish, the published message will only be delivered to subscribing\ndevices that are at most the specified distance from this device.\n\nIf used with a subscribe, messages will only be delivered if the publishing device\nis at most the specified distance from this device. \n\n##### Parameters\n\n| distanceType | One of `Strategy.DISTANCE_TYPE_*` specifying how close nearby devices must be. |\n|--------------|--------------------------------------------------------------------------------|\n\n#### public [Strategy.Builder](/android/reference/com/google/android/gms/nearby/messages/Strategy.Builder)\n**setTtlSeconds** (int ttlSeconds)\n\nSets the time to live in seconds for the publish or subscribe. This must be either\n[Strategy.TTL_SECONDS_INFINITE](/android/reference/com/google/android/gms/nearby/messages/Strategy#TTL_SECONDS_INFINITE), or a positive integer between 1 and\n[Strategy.TTL_SECONDS_MAX](/android/reference/com/google/android/gms/nearby/messages/Strategy#TTL_SECONDS_MAX), inclusive.\n\nIf not set, [Strategy.TTL_SECONDS_DEFAULT](/android/reference/com/google/android/gms/nearby/messages/Strategy#TTL_SECONDS_DEFAULT) is used instead."]]