Wi-Fi Network Request API for peer-to-peer connectivity
Stay organized with collections
Save and categorize content based on your preferences.
On Android 10 (API level 29) and higher devices, you can use a new peer to peer API to
bootstrap configuration for secondary devices like Chromecast and Google Home
hardware. This feature enables your app to prompt the user to change the access
point that the device is connected to by using
WifiNetworkSpecifier
to describe properties of a requested network.
Set a network filter to match networks to connect to, along with required
credentials.
Decide on a combination of SSID,
SSID pattern,
BSSID,
and BSSID pattern
to set the network filter in each request, subject to the following
requirements:
Each request should provide at least one of SSID, SSID pattern,
BSSID, or BSSID pattern
Each request can set only one of SSID or SSID pattern
Each request can set only one of BSSID or BSSID pattern
Add the specifiers to the network request along with a
NetworkCallback
instance to track the status of the request.
If the user accepts the request and the connection to the network is
successful,
NetworkCallback.onAvailable()
is invoked on the callback object. If the user denies the request or if the
connection to the network is unsuccessful,
NetworkCallback.onUnavailable()
is invoked on the callback object.
Initiating the request to connect to a peer device launches a dialog box on the
same device, from which that device's user can accept the connection request.
Bypassing user approval
Once the user approves a network to connect to in response to a request from a
specific app, the device stores the approval for the particular access point.
If the app makes a specific request to
connect to that access point again, the device skips the user approval phase
and automatically connects to the network. If the user chooses to forget the
network while connected to a network requested by the API, then this stored
approval for that combination of app and network is removed, and any future
request from the app must be approved by the user again. If the app
makes a non-specific request, such as with an SSID or BSSID pattern, then the
user must approve the request.
Code sample
The following code sample shows how to connect to an open network with an SSID
prefix of "test" and a BSSID OUI of "10:03:23":
Kotlin
valspecifier=WifiNetworkSpecifier.Builder().setSsidPattern(PatternMatcher("test",PatternMatcher.PATTERN_PREFIX)).setBssidPattern(MacAddress.fromString("10:03:23:00:00:00"),MacAddress.fromString("ff:ff:ff:00:00:00")).build()valrequest=NetworkRequest.Builder().addTransportType(NetworkCapabilities.TRANSPORT_WIFI).removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).setNetworkSpecifier(specifier).build()valconnectivityManager=context.getSystemService(Context.CONNECTIVITY_SERVICE)asConnectivityManagervalnetworkCallback=object:ConnectivityManager.NetworkCallback(){...overridefunonAvailable(network:Network?){// do success processing here..}overridefunonUnavailable(){// do failure processing here..}...}connectivityManager.requestNetwork(request,networkCallback)...// Release the request when done.connectivityManager.unregisterNetworkCallback(networkCallback)
Java
finalNetworkSpecifierspecifier=newWifiNetworkSpecifier.Builder().setSsidPattern(newPatternMatcher("test",PatternMatcher.PATTERN_PREFIX)).setBssidPattern(MacAddress.fromString("10:03:23:00:00:00"),MacAddress.fromString("ff:ff:ff:00:00:00")).build();finalNetworkRequestrequest=newNetworkRequest.Builder().addTransportType(NetworkCapabilities.TRANSPORT_WIFI).removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).setNetworkSpecifier(specifier).build();finalConnectivityManagerconnectivityManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);finalNetworkCallbacknetworkCallback=newNetworkCallback(){...@OverridevoidonAvailable(...){// do success processing here..}@OverridevoidonUnavailable(...){// do failure processing here..}...};connectivityManager.requestNetwork(request,networkCallback);...// Release the request when done.connectivityManager.unregisterNetworkCallback(networkCallback);
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[],[],null,["# Wi-Fi Network Request API for peer-to-peer connectivity\n\nOn Android 10 (API level 29) and higher devices, you can use a new peer to peer API to\nbootstrap configuration for secondary devices like Chromecast and Google Home\nhardware. This feature enables your app to prompt the user to change the access\npoint that the device is connected to by using\n[`WifiNetworkSpecifier`](/reference/android/net/wifi/WifiNetworkSpecifier)\nto describe properties of a requested network.\n\nTo use this API, do the following:\n\n1. Create a Wi-Fi network specifier using\n [`WifiNetworkSpecifier.Builder`](/reference/android/net/wifi/WifiNetworkSpecifier.Builder).\n\n2. Set a network filter to match networks to connect to, along with required\n credentials.\n\n3. Decide on a combination of [`SSID`](/reference/android/net/wifi/WifiNetworkSpecifier.Builder#setssid),\n [`SSID pattern`](/reference/android/net/wifi/WifiNetworkSpecifier.Builder#setssidpattern),\n [`BSSID`](/reference/android/net/wifi/WifiNetworkSpecifier.Builder#setbssid),\n and [`BSSID pattern`](/reference/android/net/wifi/WifiNetworkSpecifier.Builder#setbssidpattern)\n to set the network filter in each request, subject to the following\n requirements:\n\n - Each request should provide at least one of `SSID`, `SSID pattern`, `BSSID`, or `BSSID pattern`\n - Each request can set only one of `SSID` or `SSID pattern`\n - Each request can set only one of `BSSID` or `BSSID pattern`\n4. Add the specifiers to the network request along with a\n [`NetworkCallback`](/reference/android/net/ConnectivityManager.NetworkCallback)\n instance to track the status of the request.\n\n If the user accepts the request and the connection to the network is\n successful,\n [`NetworkCallback.onAvailable()`](/reference/android/net/ConnectivityManager.NetworkCallback#onAvailable(android.net.Network))\n is invoked on the callback object. If the user denies the request or if the\n connection to the network is unsuccessful,\n [`NetworkCallback.onUnavailable()`](/reference/android/net/ConnectivityManager.NetworkCallback#onUnavailable())\n is invoked on the callback object.\n\nInitiating the request to connect to a peer device launches a dialog box on the\nsame device, from which that device's user can accept the connection request.\n| **Note:** Creating a connection using this API does not provide an internet connection to the app or to the device. To provide an internet connection to the apps on a device, use the [Wi-Fi Suggestion API](/develop/connectivity/wifi/wifi-suggest) instead.\n\nBypassing user approval\n-----------------------\n\nOnce the user approves a network to connect to in response to a request from a\nspecific app, the device stores the approval for the particular access point.\nIf the app makes a specific request to\nconnect to that access point again, the device skips the user approval phase\nand automatically connects to the network. If the user chooses to forget the\nnetwork while connected to a network requested by the API, then this stored\napproval for that combination of app and network is removed, and any future\nrequest from the app must be approved by the user again. If the app\nmakes a non-specific request, such as with an SSID or BSSID pattern, then the\nuser must approve the request.\n\nCode sample\n-----------\n\nThe following code sample shows how to connect to an open network with an SSID\nprefix of `\"test\"` and a BSSID OUI of `\"10:03:23\"`: \n\n### Kotlin\n\n```kotlin\nval specifier = WifiNetworkSpecifier.Builder()\n .setSsidPattern(PatternMatcher(\"test\", PatternMatcher.PATTERN_PREFIX))\n .setBssidPattern(MacAddress.fromString(\"10:03:23:00:00:00\"), MacAddress.fromString(\"ff:ff:ff:00:00:00\"))\n .build()\n\nval request = NetworkRequest.Builder()\n .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)\n .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)\n .setNetworkSpecifier(specifier)\n .build()\n\nval connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager\n\nval networkCallback = object : ConnectivityManager.NetworkCallback() {\n ...\n override fun onAvailable(network: Network?) {\n // do success processing here..\n }\n\n override fun onUnavailable() {\n // do failure processing here..\n }\n ...\n}\nconnectivityManager.requestNetwork(request, networkCallback)\n...\n// Release the request when done.\nconnectivityManager.unregisterNetworkCallback(networkCallback)\n```\n\n### Java\n\n```java\nfinal NetworkSpecifier specifier =\n new WifiNetworkSpecifier.Builder()\n .setSsidPattern(new PatternMatcher(\"test\", PatternMatcher.PATTERN_PREFIX))\n .setBssidPattern(MacAddress.fromString(\"10:03:23:00:00:00\"), MacAddress.fromString(\"ff:ff:ff:00:00:00\"))\n .build();\n\nfinal NetworkRequest request =\n new NetworkRequest.Builder()\n .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)\n .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)\n .setNetworkSpecifier(specifier)\n .build();\n\nfinal ConnectivityManager connectivityManager = (ConnectivityManager)\n context.getSystemService(Context.CONNECTIVITY_SERVICE);\n\nfinal NetworkCallback networkCallback = new NetworkCallback() {\n ...\n @Override\n void onAvailable(...) {\n // do success processing here..\n }\n\n @Override\n void onUnavailable(...) {\n // do failure processing here..\n }\n ...\n};\nconnectivityManager.requestNetwork(request, networkCallback);\n...\n// Release the request when done.\nconnectivityManager.unregisterNetworkCallback(networkCallback);\n```"]]