com.google.android.gms.nearby.connection.Connections |
Entry point for advertising and discovering nearby apps and services, and communicating with them over established connections.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Connections.ConnectionRequestListener |
This class is deprecated.
Use ConnectionLifecycleCallback instead.
|
||||||||||
Connections.ConnectionResponseCallback |
This interface is deprecated.
Use ConnectionLifecycleCallback instead.
|
||||||||||
Connections.EndpointDiscoveryListener |
This class is deprecated.
Use EndpointDiscoveryCallback
instead.
|
||||||||||
Connections.MessageListener |
This interface is deprecated.
Use PayloadCallback instead.
|
||||||||||
Connections.StartAdvertisingResult | Result delivered when a local endpoint starts being advertised. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
long | DURATION_INDEFINITE | This constant is deprecated. Durations are no longer supported. | |||||||||
int | MAX_BYTES_DATA_SIZE | This specifies the maximum allowed size of BYTES Payload s sent via
the sendPayload(GoogleApiClient, String, Payload) method. |
|||||||||
int | MAX_RELIABLE_MESSAGE_LEN |
This constant is deprecated.
Use MAX_BYTES_DATA_SIZE .
|
|||||||||
int | MAX_UNRELIABLE_MESSAGE_LEN |
This constant is deprecated.
Use MAX_BYTES_DATA_SIZE .
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Accepts a connection to a remote endpoint.
| |||||||||||
This method is deprecated.
Use
acceptConnection(GoogleApiClient, String, PayloadCallback) instead.
| |||||||||||
Disconnects from a remote endpoint.
| |||||||||||
Rejects a connection to a remote endpoint.
| |||||||||||
This method is deprecated.
Use
rejectConnection(GoogleApiClient, String) instead.
| |||||||||||
Sends a request to connect to a remote endpoint.
| |||||||||||
This method is deprecated.
Use
requestConnection(GoogleApiClient, String, String, ConnectionLifecycleCallback) instead.
| |||||||||||
Sends a
Payload to a remote endpoint. | |||||||||||
Variant of
sendPayload(GoogleApiClient, String, Payload) that takes a list of remote
endpoint IDs. | |||||||||||
This method is deprecated.
Use
sendPayload(GoogleApiClient, List, Payload) with BYTES instead.
| |||||||||||
This method is deprecated.
Use
sendPayload(GoogleApiClient, String, Payload) with BYTES instead.
| |||||||||||
This method is deprecated.
Use
sendPayload(GoogleApiClient, String, Payload) with BYTES instead.
| |||||||||||
This method is deprecated.
Use
sendPayload(GoogleApiClient, List, Payload) with BYTES instead.
| |||||||||||
Starts advertising an endpoint for a local app.
| |||||||||||
This method is deprecated.
Use
startAdvertising(GoogleApiClient, String, String, ConnectionLifecycleCallback, AdvertisingOptions) instead.
| |||||||||||
This method is deprecated.
Use
startDiscovery(GoogleApiClient, String, EndpointDiscoveryCallback, DiscoveryOptions) instead.
| |||||||||||
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(GoogleApiClient, String, com.google.android.gms.nearby.connection.EndpointDiscoveryCallback, DiscoveryOptions) , when
the client no longer needs to discover endpoints or goes inactive. | |||||||||||
This method is deprecated.
Use
stopDiscovery(GoogleApiClient) instead. You can only discover for a
single serviceId at a time, so no need to pass in the serviceId.
|
This constant is deprecated.
Durations are no longer supported.
Value for duration meaning advertising / discovery should continue indefinitely until the application asks it to stop.
This specifies the maximum allowed size of BYTES
Payload
s sent via
the sendPayload(GoogleApiClient, String, Payload)
method.
This constant is deprecated.
Use MAX_BYTES_DATA_SIZE
.
This gives the maximum payload size supported via the sendReliableMessage(GoogleApiClient, String, byte[])
, sendConnectionRequest(GoogleApiClient, String, String, byte[], Connections.ConnectionResponseCallback, Connections.MessageListener)
, and acceptConnectionRequest(GoogleApiClient, String, byte[], Connections.MessageListener)
methods.
This constant is deprecated.
Use MAX_BYTES_DATA_SIZE
.
This gives the maximum payload size supported via the sendUnreliableMessage(GoogleApiClient, String, byte[])
methods.
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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
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 | |
---|---|
PendingResult<Status> |
PendingResult to access the status of the
operation when available.
|
This method is deprecated.
Use acceptConnection(GoogleApiClient, String, PayloadCallback)
instead.
Accepts a connection request from a remote endpoint. This method must be called before messages can be received from 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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
endpointId |
String :
The identifier for the remote endpoint that sent the connection request.
Should match the value provided in a call to onConnectionRequest(String, String, byte[]) . |
handshakeData |
byte :
Bytes of a custom message to send with the connection response. This
message must not exceed MAX_BYTES_DATA_SIZE bytes in length. |
messageListener |
Connections.MessageListener :
A listener notified when a message is received from the remote endpoint,
or it disconnects. |
Returns | |
---|---|
PendingResult<Status> |
PendingResult 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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
endpointId |
String :
The identifier for the remote endpoint. Should match the value provided in a
call to onConnectionInitiated(String, ConnectionInfo) . |
Returns | |
---|---|
PendingResult<Status> |
PendingResult to access the status of the
operation when available.
|
This method is deprecated.
Use rejectConnection(GoogleApiClient, String)
instead.
Rejects a connection request from 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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
remoteEndpointId |
String :
The identifier for the remote endpoint that sent the connection
request. Should match the value provided in a call to onConnectionRequest(String, String, byte[]) . |
Returns | |
---|---|
PendingResult<Status> |
PendingResult 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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
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 | |
---|---|
PendingResult<Status> |
PendingResult to access the status of the
operation when available.
|
This method is deprecated.
Use requestConnection(GoogleApiClient, String, String, ConnectionLifecycleCallback)
instead.
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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
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. |
remoteEndpointId |
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, String, String) |
handshakeData |
byte :
Bytes of a custom message to send with the connection request. This
message must not exceed MAX_RELIABLE_MESSAGE_LEN bytes in length. |
connectionResponseCallback |
Connections.ConnectionResponseCallback :
A callback notified when the remote endpoint sends a response
to the connection request. |
messageListener |
Connections.MessageListener :
A listener notified when a message is received from the remote endpoint,
or it disconnects. |
Returns | |
---|---|
PendingResult<Status> |
PendingResult 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)
.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
endpointId |
String :
The identifier for the remote endpoint to which the payload should be sent. |
payload |
Payload :
The Payload to be sent. |
Returns | |
---|---|
PendingResult<Status> |
PendingResult to access the status of the
operation when available.
|
Variant of sendPayload(GoogleApiClient, 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 | |
---|---|
apiClient |
GoogleApiClient
|
endpointIds |
List
|
payload |
Payload
|
Returns | |
---|---|
PendingResult<Status> |
This method is deprecated.
Use sendPayload(GoogleApiClient, List, Payload)
with BYTES
instead.
Variant of sendReliableMessage(GoogleApiClient, String, byte[])
that takes a list of
remote endpoint IDs.
Parameters | |
---|---|
apiClient |
GoogleApiClient
|
remoteEndpointIds |
List
|
payload |
byte
|
This method is deprecated.
Use sendPayload(GoogleApiClient, String, Payload)
with BYTES
instead.
Sends a message to a remote endpoint using a reliable protocol. Reliable messages will be retried until delivered, and are delivered in the order they were sent to a given endpoint. Messages can only be sent to remote endpoints once a connection request was first sent and accepted (in either direction).
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
remoteEndpointId |
String :
The identifier for the remote endpoint to which the message should be
sent. |
payload |
byte :
The bytes of the message to send to the remote endpoint. This message must not
exceed MAX_RELIABLE_MESSAGE_LEN bytes in length. |
This method is deprecated.
Use sendPayload(GoogleApiClient, String, Payload)
with BYTES
instead.
Sends a message to a remote endpoint using an unreliable protocol. Unreliable messages may be dropped or delivered out of order. Messages can only be sent to remote endpoints once a connection request was first sent and accepted (in either direction).
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
remoteEndpointId |
String :
The identifier for the remote endpoint to which the message should be
sent. |
payload |
byte :
The bytes of the message to send to the remote endpoint. This message must not
exceed MAX_UNRELIABLE_MESSAGE_LEN bytes in length. |
This method is deprecated.
Use sendPayload(GoogleApiClient, List, Payload)
with BYTES
instead.
Variant of sendUnreliableMessage(GoogleApiClient, String, byte[])
that takes a list of
remote endpoint IDs.
Parameters | |
---|---|
apiClient |
GoogleApiClient
|
remoteEndpointIds |
List
|
payload |
byte
|
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(GoogleApiClient)
first.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
name |
String :
A human readable name for this endpoint, to appear on other devices. If null or
empty, a name will be generated based on the device name or model. |
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 | |
---|---|
PendingResult<Connections.StartAdvertisingResult> |
PendingResult to access the data when
available.
|
This method is deprecated.
Use startAdvertising(GoogleApiClient, String, String, ConnectionLifecycleCallback, AdvertisingOptions)
instead.
Starts advertising an endpoint for a local app.
Possible result status codes include:
STATUS_OK
if advertising started successfully.
STATUS_ALREADY_DISCOVERING
if the app is currently
discovering.
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(GoogleApiClient)
first.
To advertise an endpoint you must specify a service ID in a meta-data tag with the name
com.google.android.gms.nearby.connection.SERVICE_ID
inside your application tag,
like so:
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
name |
String :
A human readable name for this endpoint, to appear on other devices. If null or
empty, a name will be generated based on the device name or model. |
appMetadata |
AppMetadata :
Metadata used to describe this application which can be used to prompt the
user to launch or install the application. If null, only applications looking for the
specified service ID will be able to discover this endpoint. |
durationMillis |
long :
The duration of the advertisement in milliseconds, unless stopAdvertising(com.google.android.gms.common.api.GoogleApiClient) is called first. If
DURATION_INDEFINITE is passed in, the advertisement will continue indefinitely
until stopAdvertising(com.google.android.gms.common.api.GoogleApiClient) is
called. |
connectionRequestListener |
Connections.ConnectionRequestListener :
A listener notified when remote endpoints request a connection
to this endpoint. |
Returns | |
---|---|
PendingResult<Connections.StartAdvertisingResult> |
PendingResult to access the data when
available. |
This method is deprecated.
Use startDiscovery(GoogleApiClient, String, EndpointDiscoveryCallback, DiscoveryOptions)
instead.
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_ALREADY_ADVERTISING
if the app is currently
advertising.
STATUS_OUT_OF_ORDER_API_CALL
if the app is currently
connected to remote endpoints; call stopAllEndpoints(GoogleApiClient)
first.
CONNECTIONS_API
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
serviceId |
String :
The ID for the service to be discovered, as specified in its manifest. |
durationMillis |
long :
The duration of discovery in milliseconds, unless stopDiscovery(com.google.android.gms.common.api.GoogleApiClient, String) is called first.
If DURATION_INDEFINITE is passed in, discovery will continue indefinitely until
stopDiscovery(com.google.android.gms.common.api.GoogleApiClient, String) is
called. |
listener |
Connections.EndpointDiscoveryListener :
A listener notified when a remote endpoint is discovered. |
Returns | |
---|---|
PendingResult<Status> |
PendingResult 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(GoogleApiClient)
first.
CONNECTIONS_API
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
serviceId |
String :
The ID for the service to be discovered, as specified in the corresponding
call to startAdvertising(GoogleApiClient, String, String, ConnectionLifecycleCallback, AdvertisingOptions) . |
endpointDiscoveryCallback |
EndpointDiscoveryCallback :
A callback notified when a remote endpoint is discovered. |
options |
DiscoveryOptions :
The options for discovery. |
Returns | |
---|---|
PendingResult<Status> |
PendingResult to access the status of the
operation when available.
|
Stops advertising a local endpoint. Should be called after calling startAdvertising(GoogleApiClient, 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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call.
|
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(GoogleApiClient)
or startDiscovery(GoogleApiClient, String, EndpointDiscoveryCallback, DiscoveryOptions)
as
needed. After calling stopAllEndpoints(GoogleApiClient)
, no further operations with remote endpoints
will be possible until a new call to one of startAdvertising(GoogleApiClient, String, String, ConnectionLifecycleCallback, AdvertisingOptions)
or startDiscovery(GoogleApiClient, String, EndpointDiscoveryCallback, DiscoveryOptions)
.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call.
|
Stops discovery for remote endpoints, after a previous call to startDiscovery(GoogleApiClient, String, com.google.android.gms.nearby.connection.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.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the call.
|
This method is deprecated.
Use stopDiscovery(GoogleApiClient)
instead. You can only discover for a
single serviceId at a time, so no need to pass in the serviceId.
Stops discovery for remote endpoints with the specified service ID. Should be called after
calling startDiscovery(com.google.android.gms.common.api.GoogleApiClient, String, long, EndpointDiscoveryListener)
, with the same service ID value, as soon as the client no longer
needs to discover endpoints or goes inactive. Messages can still be sent to remote endpoints
after discovery ends.
Required API: CONNECTIONS_API
Required Scopes: None
Parameters | |
---|---|
apiClient |
GoogleApiClient :
The GoogleApiClient to service the
call. |
serviceId |
String :
The ID for the service to stop being discovered. |