Added in API level 29

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:

Summary

Public constructors

Public methods
WifiP2pConfig

Build WifiP2pConfig given the current requests made on the builder.

WifiP2pConfig.Builder

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

Specify the band to use for creating the group or joining the group.

WifiP2pConfig.Builder

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

Builder

Added in API level 29
Builder()

Public methods

build

Added in API level 29
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

Added in API level 29
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

Added in API level 29
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

Added in API level 34
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

Added in API level 29
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

Added in API level 29
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

Added in API level 29
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

Added in API level 29
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.