java.lang.Object | ||
↳ | com.google.android.gms.common.api.GoogleApi<com.google.android.gms.common.api.Api.ApiOptions.NoOptions> | |
↳ | com.google.android.gms.nearby.connection.ConnectionsClient |
Entry point for advertising and discovering nearby apps and services, and communicating with them over established connections.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MAX_BYTES_DATA_SIZE | This specifies the maximum allowed size of BYTES Payload s sent via
the sendPayload(String, Payload) method. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Accepts a connection to a remote endpoint.
| |||||||||||
Cancels a
Payload currently in-flight to or from remote endpoint(s). | |||||||||||
Disconnects from a remote endpoint.
| |||||||||||
Rejects a connection to a remote endpoint.
| |||||||||||
Sends a request to connect to a remote endpoint.
| |||||||||||
Sends a
Payload to a remote endpoint. | |||||||||||
Variant of
sendPayload(String, Payload) that takes a list of remote endpoint IDs. | |||||||||||
Starts advertising an endpoint for a local app.
| |||||||||||
Starts discovery for remote endpoints with the specified service ID.
| |||||||||||
Stops advertising a local endpoint.
| |||||||||||
Disconnects from, and removes all traces of, all connected and/or discovered endpoints.
| |||||||||||
Stops discovery for remote endpoints, after a previous call to
startDiscovery(String, EndpointDiscoveryCallback, DiscoveryOptions) , when the client no longer needs to discover
endpoints or goes inactive. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
This specifies the maximum allowed size of BYTES
Payload
s sent via
the sendPayload(String, Payload)
method.
Accepts a connection to a remote endpoint. This method must be called before Payload
s
can be exchanged with the remote endpoint.
Possible result status codes include:
STATUS_OK
if the connection request was accepted.
STATUS_ALREADY_CONNECTED_TO_ENDPOINT
if the app already
has a connection to the specified endpoint.
Parameters | |
---|---|
endpointId |
String : The identifier for the remote endpoint. Should match the value provided in a
call to onConnectionInitiated(String, ConnectionInfo) . |
payloadCallback |
PayloadCallback : A callback for payloads exchanged with the remote endpoint. |
Returns | |
---|---|
Task<Void> |
Task to access the status of the operation when available.
|
Disconnects from a remote endpoint. Payload
s can no longer be sent to or received from
the endpoint after this method is called.
Parameters | |
---|---|
endpointId |
String : The identifier for the remote endpoint to disconnect from.
|
Rejects a connection to a remote endpoint.
Possible result status codes include:
STATUS_OK
if the connection request was rejected.
STATUS_ALREADY_CONNECTED_TO_ENDPOINT
if the app already
has a connection to the specified endpoint.
Parameters | |
---|---|
endpointId |
String : The identifier for the remote endpoint. Should match the value provided in a
call to onConnectionInitiated(String, ConnectionInfo) . |
Returns | |
---|---|
Task<Void> |
Task to access the status of the operation when available.
|
Sends a request to connect to a remote endpoint.
Possible result status codes include:
STATUS_OK
if the connection request was sent.
STATUS_ALREADY_CONNECTED_TO_ENDPOINT
if the app already
has a connection to the specified endpoint.
Parameters | |
---|---|
name |
String : A human readable name for the local endpoint, to appear on the remote endpoint. If
null or empty, a name will be generated based on the device name or model. |
endpointId |
String : The identifier for the remote endpoint to which a connection request will be
sent. Should match the value provided in a call to onEndpointFound(String, DiscoveredEndpointInfo) |
connectionLifecycleCallback |
ConnectionLifecycleCallback : A callback notified when the remote endpoint sends a
response to the connection request. |
Returns | |
---|---|
Task<Void> |
Task to access the status of the operation when available.
|
Sends a Payload
to a remote endpoint. Payloads can only be sent to remote endpoints
once a notice of connection acceptance has been delivered via onConnectionResult(String, ConnectionResolution)
Possible result status codes include:
STATUS_OUT_OF_ORDER_API_CALL
if the device has not first
performed advertisement or discovery (to set the Strategy
).
STATUS_ENDPOINT_UNKNOWN
if there's no active (or pending)
connection to the remote endpoint.
STATUS_OK
if none of the above errors occurred. Note that
this indicates that Nearby Connections will attempt to send the Payload
, but not
that the send has successfully completed yet. Errors might still occur during
transmission (and at different times for different endpoints), and will be delivered via
onPayloadTransferUpdate(String, PayloadTransferUpdate)
.
Parameters | |
---|---|
endpointId |
String : The identifier for the remote endpoint to which the payload should be sent. |
payload |
Payload : The Payload to be sent. |
Returns | |
---|---|
Task<Void> |
Task to access the status of the operation when available.
|
Variant of sendPayload(String, Payload)
that takes a list of remote endpoint IDs. If
none of the requested endpoints are connected, STATUS_ENDPOINT_UNKNOWN
will be returned.
Parameters | |
---|---|
endpointIds |
List |
payload |
Payload |
Returns | |
---|---|
Task<Void> |
Starts advertising an endpoint for a local app.
Possible result status codes include:
STATUS_OK
if advertising started successfully.
STATUS_ALREADY_ADVERTISING
if the app is already
advertising.
STATUS_OUT_OF_ORDER_API_CALL
if the app is currently
connected to remote endpoints; call stopAllEndpoints()
first.
Parameters | |
---|---|
name |
String : A human readable name for this endpoint, to appear on other devices. |
serviceId |
String : An identifier to advertise your app to other endpoints. This can be an
arbitrary string, so long as it uniquely identifies your service. A good default is to use
your app's package name. |
connectionLifecycleCallback |
ConnectionLifecycleCallback : A callback notified when remote endpoints request a
connection to this endpoint. |
options |
AdvertisingOptions : The options for advertising. |
Returns | |
---|---|
Task<Void> |
Task to access the status of the operation when available.
|
Starts discovery for remote endpoints with the specified service ID.
Possible result status codes include:
STATUS_OK
if discovery started successfully.
STATUS_ALREADY_DISCOVERING
if the app is already
discovering the specified service.
STATUS_OUT_OF_ORDER_API_CALL
if the app is currently
connected to remote endpoints; call stopAllEndpoints()
first.
Parameters | |
---|---|
serviceId |
String : The ID for the service to be discovered, as specified in the corresponding
call to startAdvertising(String, String, ConnectionLifecycleCallback, AdvertisingOptions) . |
endpointDiscoveryCallback |
EndpointDiscoveryCallback : A callback notified when a remote endpoint is discovered. |
options |
DiscoveryOptions : The options for discovery. |
Returns | |
---|---|
Task<Void> |
Task to access the status of the operation when available.
|
Stops advertising a local endpoint. Should be called after calling startAdvertising(String, String, ConnectionLifecycleCallback, AdvertisingOptions)
, as soon
as the application no longer needs to advertise itself or goes inactive. Payload
s can
still be sent to connected endpoints after advertising ends.
Disconnects from, and removes all traces of, all connected and/or discovered endpoints. This
call is expected to be preceded by a call to stopAdvertising()
or startDiscovery(String, EndpointDiscoveryCallback, DiscoveryOptions)
as needed. After calling
stopAllEndpoints()
, no further operations with remote endpoints will be possible until a
new call to one of startAdvertising(String, String, ConnectionLifecycleCallback, AdvertisingOptions)
or startDiscovery(String, EndpointDiscoveryCallback, DiscoveryOptions)
.
Stops discovery for remote endpoints, after a previous call to startDiscovery(String, EndpointDiscoveryCallback, DiscoveryOptions)
, when the client no longer needs to discover
endpoints or goes inactive. Payload
s can still be sent to connected endpoints after
discovery ends.