| CLASS info |
| public abstract class DiscoveryEngine |
| Represents the entry class for broadcasting, scanning, and connection. This class implements related methods for these features. |
| Return type | Method name |
| Task<Void> | acceptConnect(String endpointId, DataCallback dataCallback) Accepts a connection. |
| void | disconnect(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. |
| void | stopBroadcasting() Stops broadcasting. |
| void | disconnectAll() Disconnects all connections. |
| void | stopScan() Stops discovering devices. |
| 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 name | Parameter desc |
| endpointId | ID of the remote endpoint. |
| dataCallback | Callback 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 name | Parameter desc |
| endpointId | ID 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 name | Parameter desc |
| endpointId | ID 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 name | Parameter desc |
| name | Local device name. |
| endpointId | ID of the remote endpoint. |
| connectCallback | Callback 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 name | Parameter desc |
| name | Local device name. |
| serviceId | Service ID. The app package name is recommended. |
| connectCallback | Callback listener class called when detecting a connection request sent by a remote endpoint. |
| option | Broadcasting 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 name | Parameter desc |
| serviceId | Service ID. The app package name is recommended. |
| scanEndpointCallback | Callback listener class called when discovering a remote endpoint with the specified service ID. |
| option | Scanning 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. |