目录

CLASS info
public abstract class DiscoveryEngine
Represents the entry class for broadcasting, scanning, and connection. This class implements related methods for these features.

Public Method Summary

Return typeMethod name
Task<Void>acceptConnect(String endpointId, DataCallback dataCallback)
Accepts a connection.
voiddisconnect(String endpointId)
Disconnects from a remote endpoint.
Task<Void>rejectConnect(String endpointId)
Rejects a connection request from a remote endpoint.
Task<Void>requestConnect(String name, String endpointId, ConnectCallback connectCallback)
Sends a request to connect to a remote endpoint.
Task<Void>startBroadcasting(String name, String serviceId, ConnectCallback connectCallback, BroadcastOption option)
Starts broadcasting.
Task<Void>startScan(String serviceId, ScanEndpointCallback scanEndpointCallback, ScanOption option)
Starts to scan for remote endpoints with the specified serviceId.
voidstopBroadcasting()
Stops broadcasting.
voiddisconnectAll()
Disconnects all connections.
voidstopScan()
Stops discovering devices.

Public Methods

Method
public abstract Task<Void> acceptConnect(String endpointId, DataCallback dataCallback)
Accepts a connection. This API must be called before data transmission. The result code STATUS_SUCCESS indicates that the connection is accepted and the result code STATUS_ALREADY_CONNECTED indicates that the app has already been connected to the remote endpoint.

Parameters

Parameter nameParameter desc
endpointIdID of the remote endpoint.
dataCallbackCallback class called after data is received.
Method
public abstract void disconnect(String endpointId)
Disconnects from a remote endpoint. Then communication with the remote endpoint is no longer available.

Parameters

Parameter nameParameter desc
endpointIdID of the remote endpoint.
Method
public abstract Task<Void> rejectConnect(String endpointId)
Rejects a connection request from a remote endpoint. The result code STATUS_SUCCESS indicates that the connection is successfully rejected. The result code STATUS_ALREADY_CONNECTED indicates that the app has been connected to the remote endpoint.

Parameters

Parameter nameParameter desc
endpointIdID of the remote endpoint.
Method
public abstract Task<Void> requestConnect(String name, String endpointId,
ConnectCallback connectCallback)
Sends a request to connect to a remote endpoint.
STATUS_SUCCESS: The connection request is sent.
STATUS_ALREADY_CONNECTED: The app has already been connected to the remote endpoint.
STATUS_BLUETOOTH_OPERATION_FAILED: The connection fails due to a Bluetooth error.
STATUS_FAILURE: The connection failed due to another reason.

Parameters

Parameter nameParameter desc
nameLocal device name.
endpointIdID of the remote endpoint.
connectCallbackCallback listener class called during connection.
Method
public abstract Task<Void> startBroadcasting(String name, String serviceId, ConnectCallback connectCallback, BroadcastOption option)
Starts broadcasting. The result codes are described as follows:
STATUS_SUCCESS: Broadcasting started successfully.
STATUS_ALREADY_BROADCASTING: The app is broadcasting.
STATUS_API_DISORDER: API calls are out of order.

Parameters

Parameter nameParameter desc
nameLocal device name.
serviceIdService ID. The app package name is recommended.
connectCallbackCallback listener class called when detecting a connection request sent by a remote endpoint.
optionBroadcasting options specified in the connection policy.
Method
public abstract Task<Void> startScan(String serviceId, ScanEndpointCallback scanEndpointCallback, ScanOption option)
Starts to scan for remote endpoints with the specified service ID. The result codes are described as follows:
STATUS_SUCCESS: Scanning started successfully.
STATUS_ALREADY_SCANNING: The app has discovered the service.
STATUS_API_DISORDER: API calls are out of order.

Parameters

Parameter nameParameter desc
serviceIdService ID. The app package name is recommended.
scanEndpointCallbackCallback listener class called when discovering a remote endpoint with the specified service ID.
optionScanning options specified in the connection policy.
Method
public abstract void stopBroadcasting()
Stops broadcasting.
Method
public abstract void disconnectAll()
Disconnects all connections.
Method
public abstract void stopScan()
Stops discovering devices.