public final class WifiP2pController extends Object
The management operations include initializing the Wi-Fi P2P service, discovering peer services and devices, creating a P2P group, and connecting to a specified peer device.
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
DEVICE_INFO_REQUEST |
Indicates the request for the Wi-Fi P2P device information.
|
static int |
DEVICE_LIST_REQUEST |
Indicates the request for the list of Wi-Fi P2P devices.
|
static int |
GROUP_INFO_REQUEST |
Indicates the request for the Wi-Fi P2P group information.
|
static int |
NETWORK_INFO_REQUEST |
Indicates the request for the Wi-Fi P2P network information.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
cancelConnect(WifiP2pCallback callback) |
Cancels a P2P connection that has been initiated.
|
void |
connect(WifiP2pConfig wifiP2pConfig,
WifiP2pCallback callback) |
Initiates a P2P connection to a device with the specified configuration.
|
void |
createGroup(WifiP2pConfig wifiP2pConfig,
WifiP2pCallback callback) |
Creates a P2P group.
|
void |
discoverDevices(WifiP2pCallback callback) |
Discovers Wi-Fi P2P devices.
|
static WifiP2pController |
getInstance(Context context) |
Obtains a
WifiP2pController instance. |
IRemoteObject |
init(EventRunner eventRunner,
WifiP2pCallback callback) |
Initializes the P2P controller and enables Wi-Fi P2P capabilities.
|
void |
removeGroup(WifiP2pCallback callback) |
Removes a P2P group.
|
void |
requestP2pInfo(int requestType,
WifiP2pCallback callback) |
Requests P2P information.
|
void |
stopDeviceDiscovery(WifiP2pCallback callback) |
Stops discovering Wi-Fi P2P devices.
|
public static final int DEVICE_INFO_REQUEST
Your application can use requestP2pInfo(int,ohos.wifi.p2p.WifiP2pCallback)
to request the Wi-Fi P2P device information.
public static final int DEVICE_LIST_REQUEST
Your application can use requestP2pInfo(int,ohos.wifi.p2p.WifiP2pCallback)
to request the list of Wi-Fi P2P devices.
public static final int GROUP_INFO_REQUEST
Your application can use requestP2pInfo(int,ohos.wifi.p2p.WifiP2pCallback)
to request the Wi-Fi P2P group information.
public static final int NETWORK_INFO_REQUEST
Your application can use requestP2pInfo(int,ohos.wifi.p2p.WifiP2pCallback)
to request the Wi-Fi P2P network information.
public static WifiP2pController getInstance(Context context) throws IllegalArgumentException
WifiP2pController instance.
WifiP2pController is a singleton class.
context - Indicates the application context of the caller.WifiP2pController instance.IllegalArgumentException - if the caller is missing required context.public IRemoteObject init(EventRunner eventRunner, WifiP2pCallback callback) throws RemoteException
This method is used to establish a communication channel between devices. Before calling other Wi-Fi P2P-related methods, you must call this method first. Otherwise, calling other methods will fail.
eventRunner - Indicates the event runner that receives callbacks.callback - Indicates the callback that is invoked to notify the P2P information.RemoteException - Throws this exception if the WifiP2pController object is initialized failed.public void discoverDevices(WifiP2pCallback callback) throws RemoteException
The discovery result is notified by the callback passed by your application.
Before calling this method, ensure that the WifiP2pController object has been initialized
using the init(ohos.eventhandler.EventRunner,ohos.wifi.p2p.WifiP2pCallback) method.
callback - Indicates the callback that is invoked to notify the discovery result.RemoteException - Throws this exception if the WifiP2pController object is not initialized.public void stopDeviceDiscovery(WifiP2pCallback callback) throws RemoteException
The result of stopping the discovery is notified by the callback passed by your application.
Before calling this method, ensure that the WifiP2pController object has been initialized
using the init(ohos.eventhandler.EventRunner,ohos.wifi.p2p.WifiP2pCallback) method.
callback - Indicates the callback that is invoked to notify the result of stopping the discovery.RemoteException - Throws this exception if the WifiP2pController object is not initialized.public void createGroup(WifiP2pConfig wifiP2pConfig, WifiP2pCallback callback) throws RemoteException
The P2P group creation result is notified by the callback passed by your application.
Before calling this method, ensure that the WifiP2pController object has been initialized
using the init(ohos.eventhandler.EventRunner,ohos.wifi.p2p.WifiP2pCallback) method.
wifiP2pConfig - Indicates the P2P configuration used to create the P2P group.callback - Indicates the callback that is invoked to notify the P2P group creation result.RemoteException - Throws this exception if the WifiP2pController object is not initialized.public void removeGroup(WifiP2pCallback callback) throws RemoteException
The P2P group removal result is notified by the callback passed by your application.
Before calling this method, ensure that the WifiP2pController object has been initialized
using the init(ohos.eventhandler.EventRunner,ohos.wifi.p2p.WifiP2pCallback) method.
callback - Indicates the callback that is invoked to notify the P2P group removal result.RemoteException - Throws this exception if the WifiP2pController object is not initialized.public void requestP2pInfo(int requestType,
WifiP2pCallback callback)
throws RemoteException
The P2P information is notified by the callback passed by your application.
Before calling this method, ensure that the WifiP2pController object has been initialized
using the init(ohos.eventhandler.EventRunner,ohos.wifi.p2p.WifiP2pCallback) method.
requestType - Indicates the request type, which can be GROUP_INFO_REQUEST,
DEVICE_INFO_REQUEST, NETWORK_INFO_REQUEST or DEVICE_LIST_REQUEST.callback - Indicates the callback that is invoked to notify the P2P information.RemoteException - Throws this exception if the WifiP2pController object is not initialized.public void connect(WifiP2pConfig wifiP2pConfig, WifiP2pCallback callback) throws RemoteException
The result of initiating the P2P connection is notified by the callback passed by your application.
Before calling this method, ensure that the WifiP2pController object has been initialized
using the init(ohos.eventhandler.EventRunner,ohos.wifi.p2p.WifiP2pCallback) method.
wifiP2pConfig - Indicates the P2P configuration of the device to connect to.callback - Indicates the callback that is invoked to notify the result of initiating the P2P connection.RemoteException - Throws this exception if the WifiP2pController object is not initialized.public void cancelConnect(WifiP2pCallback callback) throws RemoteException
The cancellation result is notified by the callback passed by your application.
Before calling this method, ensure that the WifiP2pController object has been initialized
using the init(ohos.eventhandler.EventRunner,ohos.wifi.p2p.WifiP2pCallback) method.
callback - Indicates the callback that is invoked to notify the cancellation result.RemoteException - Throws this exception if the WifiP2pController object is not initialized.