Builder
class Builder
kotlin.Any | |
↳ | android.net.wifi.p2p.WifiP2pConfig.Builder |
Builder used to build WifiP2pConfig
objects for creating or joining a group. The WifiP2pConfig can be constructed for two use-cases:
- SSID + Passphrase are known: use
setNetworkName(java.lang.String)
andsetPassphrase(java.lang.String)
. - SSID or Passphrase is unknown, in such a case the MAC address must be known and specified using
setDeviceAddress(android.net.MacAddress)
.
Summary
Public constructors | |
---|---|
Builder() |
Public methods | |
---|---|
WifiP2pConfig |
build() Build |
WifiP2pConfig.Builder |
enablePersistentMode(persistent: Boolean) Specify that the group configuration be persisted (i.e. saved). |
WifiP2pConfig.Builder |
setDeviceAddress(deviceAddress: MacAddress?) Specify the peer's MAC address. |
WifiP2pConfig.Builder |
setGroupClientIpProvisioningMode(groupClientIpProvisioningMode: Int) Specify the IP provisioning mode when joining a group as a group client. |
WifiP2pConfig.Builder |
setGroupOperatingBand(band: Int) Specify the band to use for creating the group or joining the group. |
WifiP2pConfig.Builder |
setGroupOperatingFrequency(frequency: Int) Specify the frequency, in MHz, to use for creating the group or joining the group. |
WifiP2pConfig.Builder |
setNetworkName(networkName: String) Specify the network name, a. |
WifiP2pConfig.Builder |
setPassphrase(passphrase: String) Specify the passphrase for creating or joining a group. |
Public constructors
Public methods
build
fun build(): WifiP2pConfig
Build WifiP2pConfig
given the current requests made on the builder.
Return | |
---|---|
WifiP2pConfig |
WifiP2pConfig constructed based on builder method calls. This value cannot be null . |
enablePersistentMode
fun enablePersistentMode(persistent: Boolean): WifiP2pConfig.Builder
Specify that the group configuration be persisted (i.e. saved). By default the group configuration will not be saved.
Optional. false by default.
Parameters | |
---|---|
persistent |
Boolean: is this group persistent group. |
Return | |
---|---|
WifiP2pConfig.Builder |
The builder to facilitate chaining builder.setXXX(..).setXXX(..) . This value cannot be null . |
setDeviceAddress
fun setDeviceAddress(deviceAddress: MacAddress?): WifiP2pConfig.Builder
Specify the peer's MAC address. If not set, the device will try to find a peer whose SSID matches the network name as specified by setNetworkName(java.lang.String)
. Specifying null will reset the peer's MAC address to "02:00:00:00:00:00".
Optional. "02:00:00:00:00:00" by default.
If the network name is not set, the peer's MAC address is mandatory.
Parameters | |
---|---|
deviceAddress |
MacAddress?: the peer's MAC address. This value may be null . |
Return | |
---|---|
WifiP2pConfig.Builder |
The builder to facilitate chaining builder.setXXX(..).setXXX(..) . |
setGroupClientIpProvisioningMode
fun setGroupClientIpProvisioningMode(groupClientIpProvisioningMode: Int): WifiP2pConfig.Builder
Specify the IP provisioning mode when joining a group as a group client. The IP provisioning mode should be GROUP_CLIENT_IP_PROVISIONING_MODE_IPV4_DHCP
or GROUP_CLIENT_IP_PROVISIONING_MODE_IPV6_LINK_LOCAL
.
When joining a group as group client using android.net.wifi.p2p.WifiP2pManager#connect(android.net.wifi.p2p.WifiP2pManager.Channel,android.net.wifi.p2p.WifiP2pConfig,android.net.wifi.p2p.WifiP2pManager.ActionListener)
, specifying GROUP_CLIENT_IP_PROVISIONING_MODE_IPV4_DHCP
directs the system to assign a IPv4 to the group client using DHCP. Specifying GROUP_CLIENT_IP_PROVISIONING_MODE_IPV6_LINK_LOCAL
directs the system to assign a link-local IPv6 to the group client.
Optional. GROUP_CLIENT_IP_PROVISIONING_MODE_IPV4_DHCP
by default.
If WifiP2pManager#isGroupOwnerIPv6LinkLocalAddressProvided()
is true
and GROUP_CLIENT_IP_PROVISIONING_MODE_IPV6_LINK_LOCAL
is used then the system will discover the group owner's IPv6 link-local address and broadcast it using the WifiP2pManager#EXTRA_WIFI_P2P_INFO
extra of the WifiP2pManager#WIFI_P2P_CONNECTION_CHANGED_ACTION
broadcast. Otherwise, if WifiP2pManager#isGroupOwnerIPv6LinkLocalAddressProvided()
is false
then the group owner's IPv6 link-local address is not discovered and it is the responsibility of the caller to obtain it in some other way, e.g. via out-of-band communication.
Parameters | |
---|---|
groupClientIpProvisioningMode |
Int: the IP provisioning mode of the group client. This should be one of GROUP_CLIENT_IP_PROVISIONING_MODE_IPV4_DHCP , GROUP_CLIENT_IP_PROVISIONING_MODE_IPV6_LINK_LOCAL . Value is android.net.wifi.p2p.WifiP2pConfig#GROUP_CLIENT_IP_PROVISIONING_MODE_IPV4_DHCP , or android.net.wifi.p2p.WifiP2pConfig#GROUP_CLIENT_IP_PROVISIONING_MODE_IPV6_LINK_LOCAL |
Return | |
---|---|
WifiP2pConfig.Builder |
The builder to facilitate chaining builder.setXXX(..).setXXX(..) . This value cannot be null . |
setGroupOperatingBand
fun setGroupOperatingBand(band: Int): WifiP2pConfig.Builder
Specify the band to use for creating the group or joining the group. The band should be GROUP_OWNER_BAND_2GHZ
, GROUP_OWNER_BAND_5GHZ
or GROUP_OWNER_BAND_AUTO
.
When creating a group as Group Owner using android.net.wifi.p2p.WifiP2pManager#createGroup(android.net.wifi.p2p.WifiP2pManager.Channel,android.net.wifi.p2p.WifiP2pConfig,android.net.wifi.p2p.WifiP2pManager.ActionListener)
, specifying GROUP_OWNER_BAND_AUTO
allows the system to pick the operating frequency from all supported bands. Specifying GROUP_OWNER_BAND_2GHZ
or GROUP_OWNER_BAND_5GHZ
only allows the system to pick the operating frequency in the specified band. If the Group Owner cannot create a group in the specified band, the operation will fail.
When joining a group as Group Client using android.net.wifi.p2p.WifiP2pManager#connect(android.net.wifi.p2p.WifiP2pManager.Channel,android.net.wifi.p2p.WifiP2pConfig,android.net.wifi.p2p.WifiP2pManager.ActionListener)
, specifying GROUP_OWNER_BAND_AUTO
allows the system to scan all supported frequencies to find the desired group. Specifying GROUP_OWNER_BAND_2GHZ
or GROUP_OWNER_BAND_5GHZ
only allows the system to scan the specified band.
setGroupOperatingBand(int)
and setGroupOperatingFrequency(int)
are mutually exclusive. Setting operating band and frequency both is invalid.
Optional. GROUP_OWNER_BAND_AUTO
by default.
Parameters | |
---|---|
band |
Int: the operating band of the group. This should be one of GROUP_OWNER_BAND_AUTO , GROUP_OWNER_BAND_2GHZ , GROUP_OWNER_BAND_5GHZ . Value is android.net.wifi.p2p.WifiP2pConfig#GROUP_OWNER_BAND_AUTO , android.net.wifi.p2p.WifiP2pConfig#GROUP_OWNER_BAND_2GHZ , or android.net.wifi.p2p.WifiP2pConfig#GROUP_OWNER_BAND_5GHZ |
Return | |
---|---|
WifiP2pConfig.Builder |
The builder to facilitate chaining builder.setXXX(..).setXXX(..) . This value cannot be null . |
setGroupOperatingFrequency
fun setGroupOperatingFrequency(frequency: Int): WifiP2pConfig.Builder
Specify the frequency, in MHz, to use for creating the group or joining the group.
When creating a group as Group Owner using WifiP2pManager#createGroup(
, specifying a frequency only allows the system to pick the specified frequency. If the Group Owner cannot create a group at the specified frequency, the operation will fail. When not specifying a frequency, it allows the system to pick operating frequency from all supported bands.
When joining a group as Group Client using WifiP2pManager#connect(
, specifying a frequency only allows the system to scan the specified frequency. If the frequency is not supported or invalid, the operation will fail. When not specifying a frequency, it allows the system to scan all supported frequencies to find the desired group.
setGroupOperatingBand(int)
and setGroupOperatingFrequency(int)
are mutually exclusive. Setting operating band and frequency both is invalid.
Optional. 0 by default.
Parameters | |
---|---|
frequency |
Int: the operating frequency of the group. |
Return | |
---|---|
WifiP2pConfig.Builder |
The builder to facilitate chaining builder.setXXX(..).setXXX(..) . This value cannot be null . |
setNetworkName
fun setNetworkName(networkName: String): WifiP2pConfig.Builder
Specify the network name, a.k.a. group name, for creating or joining a group.
A network name shall begin with "DIRECT-xy". x and y are selected from the following character set: upper case letters, lower case letters and numbers. Any byte values allowed for an SSID according to IEEE802.11-2012 [1] may be included after the string "DIRECT-xy" (including none).
Must be called - an empty network name or an network name not conforming to the P2P Group ID naming rule is not valid.
Parameters | |
---|---|
networkName |
String: network name of a group. This value cannot be null . |
Return | |
---|---|
WifiP2pConfig.Builder |
The builder to facilitate chaining builder.setXXX(..).setXXX(..) . This value cannot be null . |
setPassphrase
fun setPassphrase(passphrase: String): WifiP2pConfig.Builder
Specify the passphrase for creating or joining a group.
The passphrase must be an ASCII string whose length is between 8 and 63.
Must be called - an empty passphrase is not valid.
Parameters | |
---|---|
passphrase |
String: the passphrase of a group. This value cannot be null . |
Return | |
---|---|
WifiP2pConfig.Builder |
The builder to facilitate chaining builder.setXXX(..).setXXX(..) . This value cannot be null . |