Java Examples

The following examples show how to use You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File:    From WifiUtils with Apache License 2.0 6 votes vote down vote up
static void setupWifiNetworkSpecifierSecurities(@NonNull WifiNetworkSpecifier.Builder wifiNetworkSpecifierBuilder, String security, @NonNull final String password) {
    wifiLog("Setting up WifiNetworkSpecifier.Builder " + security);
    switch (security) {
        case SECURITY_NONE:
            // nothing to do
        case SECURITY_WEP:
            // no longer possible
        case SECURITY_PSK:
        case SECURITY_EAP:

            wifiLog("Invalid security type: " + security);
Example #2
Source File:    From WifiUtils with Apache License 2.0 4 votes vote down vote up
private static boolean connectAndroidQ(@Nullable ConnectivityManager connectivityManager, @NonNull ScanResult scanResult, @NonNull String password) {
    if (connectivityManager == null) {
        return false;

    WifiNetworkSpecifier.Builder wifiNetworkSpecifierBuilder = new WifiNetworkSpecifier.Builder()

    final String security = ConfigSecurities.getSecurity(scanResult);

    ConfigSecurities.setupWifiNetworkSpecifierSecurities(wifiNetworkSpecifierBuilder, security, password);

    NetworkRequest networkRequest = new NetworkRequest.Builder()

    // not sure, if this is needed
    if (networkCallback != null) {

    networkCallback = new ConnectivityManager.NetworkCallback() {
        public void onAvailable(@NonNull Network network) {

            wifiLog("AndroidQ+ connected to wifi ");

            // bind so all api calls are performed over this new network

        public void onUnavailable() {

            wifiLog("AndroidQ+ could not connect to wifi");

    connectivityManager.requestNetwork(networkRequest, networkCallback);

    return true;
Example #3
Source File:    From DeviceConnect-Android with MIT License 4 votes vote down vote up
public void requestNetwork(final String ssId) {
    WifiNetworkSpecifier specifier = new WifiNetworkSpecifier.Builder()
    NetworkRequest request = new NetworkRequest.Builder()
    requestNetwork(ssId, request);