当前位置: 首页>>代码示例>>Java>>正文


Java WifiManager.addNetwork方法代码示例

本文整理汇总了Java中android.net.wifi.WifiManager.addNetwork方法的典型用法代码示例。如果您正苦于以下问题:Java WifiManager.addNetwork方法的具体用法?Java WifiManager.addNetwork怎么用?Java WifiManager.addNetwork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.net.wifi.WifiManager的用法示例。


在下文中一共展示了WifiManager.addNetwork方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectWifiSSID

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
 * 给温控器成功发送联网命令后,连接温控器连接的wifi节点
 *
 * @param context  上下文对象
 * @param ssid     ssid
 * @param password 密码
 */
public static void connectWifiSSID(Context context, WifiManager manager, String ssid, String
        password) {
    e("reSetNetwork----------连接设备连入的路由---" + ssid);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        e("当前手机系统>=Android6.0,采取兼容模式");
        new WifiAutoConnectManager(manager).connect(ssid, password, WifiAutoConnectManager
                .getCipherType(context, ssid));
    } else {
        int networkId = manager.addNetwork(getWifiConfiguration(manager, ssid, password));
        if (networkId != -1) {
            manager.enableNetwork(networkId, true);
        }
    }
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:22,代码来源:NetworkConnectionUtils.java

示例2: updateNetwork

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
 * Update the network: either create a new network or modify an existing network
 * @param config the new network configuration
 */
private static void updateNetwork(WifiManager wifiManager, WifiConfiguration config) {
  Integer foundNetworkID = findNetworkInExistingConfig(wifiManager, config.SSID);
  if (foundNetworkID != null) {
    Log.i(TAG, "Removing old configuration for network " + config.SSID);
    wifiManager.removeNetwork(foundNetworkID);
    wifiManager.saveConfiguration();
  }
  int networkId = wifiManager.addNetwork(config);
  if (networkId >= 0) {
    // Try to disable the current network and start a new one.
    if (wifiManager.enableNetwork(networkId, true)) {
      Log.i(TAG, "Associating to network " + config.SSID);
      wifiManager.saveConfiguration();
    } else {
      Log.w(TAG, "Failed to enable network " + config.SSID);
    }
  } else {
    Log.w(TAG, "Unable to add network " + config.SSID);
  }
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:25,代码来源:WifiConfigManager.java

示例3: updateNetwork

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
 * Update the network: either create a new network or modify an existing network
 *
 * @param config the new network configuration
 */
private static void updateNetwork(WifiManager wifiManager, WifiConfiguration config) {
    Integer foundNetworkID = findNetworkInExistingConfig(wifiManager, config.SSID);
    if (foundNetworkID != null) {
        Log.i(TAG, "Removing old configuration for network " + config.SSID);
        wifiManager.removeNetwork(foundNetworkID);
        wifiManager.saveConfiguration();
    }
    int networkId = wifiManager.addNetwork(config);
    if (networkId >= 0) {
        // Try to disable the current network and start a new one.
        if (wifiManager.enableNetwork(networkId, true)) {
            Log.i(TAG, "Associating to network " + config.SSID);
            wifiManager.saveConfiguration();
        } else {
            Log.w(TAG, "Failed to enable network " + config.SSID);
        }
    } else {
        Log.w(TAG, "Unable to add network " + config.SSID);
    }
}
 
开发者ID:xiong-it,项目名称:ZXingAndroidExt,代码行数:26,代码来源:WifiConfigManager.java

示例4: connectWifi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@ProtoMethod(description = "Connect to mContext given Wifi network with mContext given 'wpa', 'wep', 'open' type and mContext password", example = "")
@ProtoMethodParam(params = {"ssidName", "type", "password"})
public void connectWifi(String networkSSID, String type, String networkPass) {

    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String
    // should contain ssid in quotes

    if (type.equals("wep")) {
        // wep
        conf.wepKeys[0] = "\"" + networkPass + "\"";
        conf.wepTxKeyIndex = 0;
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
    } else if (type.equals("wpa")) {
        // wpa
        conf.preSharedKey = "\"" + networkPass + "\"";
    } else if (type.equals("open")) {
        // open
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    }

    WifiManager wifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.addNetwork(conf);

    List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
    for (WifiConfiguration i : list) {
        if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
            wifiManager.disconnect();
            wifiManager.enableNetwork(i.networkId, true);
            wifiManager.reconnect();

            break;
        }
    }

}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:38,代码来源:PNetwork.java

示例5: doInBackground

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {

    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + networkSSID + "\"";
    conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

    WifiManager wifiManager = (WifiManager) getBaseContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.addNetwork(conf);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
        wifiManager.startScan();
    }

    int netId = wifiManager.addNetwork(conf);
    wifiManager.disconnect();
    wifiManager.enableNetwork(netId, true);
    wifiManager.reconnect();

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(), "Joined to " + networkSSID, Toast.LENGTH_SHORT).show();
            System.out.println("SUCCESS ");
        }
    });
    return null;
}
 
开发者ID:yuvaraj119,项目名称:WifiChatSharing,代码行数:29,代码来源:MainActivity.java

示例6: connectToSocketWifi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
 * 连接指定
 *
 * @param manager
 * @param wifiSSID
 * @return
 */
public static boolean connectToSocketWifi(WifiManager manager, String wifiSSID) {
    LogUtils.i("要连接的socket wifi====>" + wifiSSID);
    WifiConfiguration wifiConfiguration = new WifiConfiguration();
    wifiConfiguration.SSID = "\"" + wifiSSID + "\"";
    wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
    wifiConfiguration.wepKeys[0] = "\"" + "\""; //小米手机MIUI7/华为EMUI4.1 需要webKey

    int networkId = manager.addNetwork(wifiConfiguration);

    if (networkId != -1) {
        manager.enableNetwork(networkId, true);
        e("连接设备成功");
        return true;
    } else {
        e("第一次连接失败,尝试第二次。");
        WifiConfiguration wifiConfiguration2 = new WifiConfiguration();
        wifiConfiguration2.SSID = "\"" + wifiSSID + "\"";
        //wifiConfiguration.wepKeys[0] = "\"" + "\"";//去掉webKey  //小米手机MIUI8不能有webKey
        wifiConfiguration2.allowedKeyManagement.set(KeyMgmt.NONE);
        networkId = manager.addNetwork(wifiConfiguration2);
        if (networkId != -1) {
            manager.enableNetwork(networkId, true);
            e("连接设备成功");
            return true;
        }
        e("连接设备失败");
    }
    return false;
}
 
开发者ID:Horrarndoo,项目名称:YiZhi,代码行数:37,代码来源:NetworkConnectionUtils.java

示例7: connect

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public void connect(String ssid, String pwd, WiFiStaConnectCallback callback){
    if(callback == null){
        return;
    }
    mCallback = callback;
    mSSID = ssid;
    mPWD = pwd;
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = "\"" + mSSID + "\"";
    if(pwd.equals("")){
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    }
    else{
        config.preSharedKey = "\"" + mPWD + "\"";
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
    }
    config.status = WifiConfiguration.Status.ENABLED;
    config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    if(!wifiManager.isWifiEnabled()){
        wifiManager.setWifiEnabled(true);
    }
    wifiManager.startScan();
    int networkId = wifiManager.addNetwork(config);
    wifiManager.disconnect();
    wifiManager.enableNetwork(networkId, true);
    wifiManager.reconnect();
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:29,代码来源:WifiSta.java

示例8: connectToAP

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public int connectToAP(Context context, String networkSSID, String networkPasskey) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    for (ScanResult result : wifiManager.getScanResults()) {
        if (result.SSID.equals(networkSSID)) {
            String securityMode = getScanResultSecurity(result);
            WifiConfiguration wifiConfiguration = createAPConfiguration(networkSSID, networkPasskey, securityMode);
            int res = wifiManager.addNetwork(wifiConfiguration);
            Log.d(TAG, "# addNetwork returned " + res);
            boolean b = wifiManager.enableNetwork(res, true);
            Log.d(TAG, "# enableNetwork returned " + b);
            wifiManager.setWifiEnabled(true);
            boolean changeHappen = wifiManager.saveConfiguration();
            if (res != -1 && changeHappen) {
                Log.d(TAG, "# Change happen: " + networkSSID);
            } else {
                Log.d(TAG, "# Change NOT happen");
            }
            return res;
        }
    }
    return -1;
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:23,代码来源:WifiUtil.java

示例9: connectToNtutcc

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static boolean connectToNtutcc(Context context) {
    try {
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = "\"" + NTUTCC_SSID + "\"";
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        wifiManager.addNetwork(conf);
        List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
        for (WifiConfiguration i : list) {
            if (i.SSID != null && i.SSID.equals("\"" + NTUTCC_SSID + "\"")) {
                wifiManager.disconnect();
                wifiManager.enableNetwork(i.networkId, true);
                wifiManager.reconnect();
                return true;
            }
        }
    } catch (Exception e) {
    }
    return false;
}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:22,代码来源:WifiUtility.java

示例10: connectWifi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
private void connectWifi() {
  info("Connecting to WiFi");

  final WifiManager manager = (WifiManager) getApplicationContext()
      .getSystemService(Context.WIFI_SERVICE);

  if (!manager.isWifiEnabled()) {
    info("Enabling WiFi");
    manager.setWifiEnabled(true);
  }

  if (!manager.startScan()) {
    info("Could not start a WiFi scan ...");
  }

  final List<android.net.wifi.ScanResult> list = manager.getScanResults();
  for (final android.net.wifi.ScanResult result : list) {
    if (result.SSID != null
        && result.SSID.startsWith("LGR105")
        && result.SSID.endsWith(".OSC")
        ) {
      info("Found WiFi candidate: " + result.capabilities);

      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);

      String networkSSID = result.SSID;
      String networkPass = prefs.getString("wifipass", "");

      WifiConfiguration conf = new WifiConfiguration();
      conf.SSID = "\"" + networkSSID + "\"";
      conf.preSharedKey = "\"" + networkPass + "\"";
      conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

      final int networkId = manager.addNetwork(conf);
      if (networkId != -1) {
        manager.disconnect();
        manager.enableNetwork(networkId, true);
        manager.saveConfiguration();
      }

      info("WiFi: Connected!");
    }
  }
}
 
开发者ID:mariobodemann,项目名称:osc,代码行数:45,代码来源:MainActivity.java

示例11: installConferenceWiFi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static void installConferenceWiFi(final Context context) {
    // Create conferenceWifiConfig
    WifiConfiguration conferenceWifiConfig = getConferenceWifiConfig();

    // Store conferenceWifiConfig.
    final WifiManager wifiManager =
            (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int netId = wifiManager.addNetwork(conferenceWifiConfig);
    if (netId != -1) {
        wifiManager.enableNetwork(netId, false);
        boolean result = wifiManager.saveConfiguration();
        if (!result) {
            Log.e(TAG, "Unknown error while calling WiFiManager.saveConfiguration()");
            Toast.makeText(context,
                    context.getResources().getString(R.string.wifi_install_error_message),
                    Toast.LENGTH_SHORT).show();
        }
    } else {
        Log.e(TAG, "Unknown error while calling WiFiManager.addNetwork()");
        Toast.makeText(context,
                context.getResources().getString(R.string.wifi_install_error_message),
                Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:25,代码来源:WiFiUtils.java

示例12: connectWifi

import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static boolean connectWifi(WifiManager wifiManager,WifiConfiguration wifiConfiguration){

        int network = wifiManager.addNetwork(wifiConfiguration);

        if (network<0)
            return false;

        return wifiManager.enableNetwork(network,true);
    }
 
开发者ID:ZhouKanZ,项目名称:SweepRobot,代码行数:10,代码来源:WifiHelper.java


注:本文中的android.net.wifi.WifiManager.addNetwork方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。