WifiNetworkSpecifier.Builder.Build Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Create a specifier object used to request a Wi-Fi network.
[Android.Runtime.Register("build", "()Landroid/net/wifi/WifiNetworkSpecifier;", "", ApiSince=29)]
public Android.Net.Wifi.WifiNetworkSpecifier Build ();
[<Android.Runtime.Register("build", "()Landroid/net/wifi/WifiNetworkSpecifier;", "", ApiSince=29)>]
member this.Build : unit -> Android.Net.Wifi.WifiNetworkSpecifier
Returns
Instance of NetworkSpecifier
.
- Attributes
Remarks
Create a specifier object used to request a Wi-Fi network. The generated NetworkSpecifier
should be used in NetworkRequest.Builder#setNetworkSpecifier(NetworkSpecifier)
when building the NetworkRequest
.
When using with ConnectivityManager#requestNetwork(NetworkRequest, NetworkCallback)
or variants, note that some devices may not support requesting a network with all combinations of specifier members. For example, some devices may only support requesting local-only networks (networks without the NetworkCapabilities#NET_CAPABILITY_INTERNET
capability), or not support requesting a particular band. However, there are no restrictions when using ConnectivityManager#registerNetworkCallback(NetworkRequest, NetworkCallback)
or other similar methods which monitor but do not request networks.
If the device can't support a request, the app will receive a call to NetworkCallback#onUnavailable()
.
When requesting a local-only network, apps can set a combination of network match params: <li> SSID Pattern using #setSsidPattern(PatternMatcher)
OR Specific SSID using #setSsid(String)
. </li> AND/OR <li> BSSID Pattern using #setBssidPattern(MacAddress, MacAddress)
OR Specific BSSID using #setBssid(MacAddress)
</li> to trigger connection to a network that matches the set params. The system will find the set of networks matching the request and present the user with a system dialog which will allow the user to select a specific Wi-Fi network to connect to or to deny the request.
To protect user privacy, some limitations to the ability of matching patterns apply. In particular, when the system brings up a network to satisfy a NetworkRequest
from some app, the system reserves the right to decline matching the SSID pattern to the real SSID of the network for other apps than the app that requested the network, and not send those callbacks even if the SSID matches the requested pattern.
For example: To connect to an open network with a SSID prefix of "test" and a BSSID OUI of "10:03:23":
{@code
final NetworkSpecifier specifier =
new Builder()
.setSsidPattern(new PatternMatcher("test", PatternMatcher.PATTERN_PREFIX))
.setBssidPattern(MacAddress.fromString("10:03:23:00:00:00"),
MacAddress.fromString("ff:ff:ff:00:00:00"))
.build()
final NetworkRequest request =
new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.setNetworkSpecifier(specifier)
.build();
final ConnectivityManager connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkCallback networkCallback = new NetworkCallback() {
...
{@literal @}Override
void onAvailable(...) {}
// etc.
};
connectivityManager.requestNetwork(request, networkCallback);
}
Java documentation for android.net.wifi.WifiNetworkSpecifier.Builder.build()
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.