當前位置: 首頁>>代碼示例>>Java>>正文


Java WifiManager.disconnect方法代碼示例

本文整理匯總了Java中android.net.wifi.WifiManager.disconnect方法的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.disconnect方法的具體用法?Java WifiManager.disconnect怎麽用?Java WifiManager.disconnect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.wifi.WifiManager的用法示例。


在下文中一共展示了WifiManager.disconnect方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: connectToKnownWifi

import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static void connectToKnownWifi(Context context, String ssid) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
    for (WifiConfiguration i : list) {
        if (i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) {
            wifiManager.disconnect();
            wifiManager.enableNetwork(i.networkId, true);
            wifiManager.reconnect();
        }
    }
}
 
開發者ID:hoanglm4,項目名稱:RxAndroidTBP,代碼行數:12,代碼來源:NetworkUtil.java

示例2: 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

示例3: 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

示例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: 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

示例6: 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


注:本文中的android.net.wifi.WifiManager.disconnect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。