Android WiFi connection programmatically

前端 未结 4 629
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 19:16

Do you have any idea how to establish a wifi connection with sending password in my android application?

4条回答
  •  忘了有多久
    2021-01-30 19:23

    100% Works.

    By this way you can connect to your specific Wifi This code for MainActivity.java

    ////////////// >>> Wifi Connection (WP2) <<< ////////////////

            WifiConfiguration wifiConfig = new WifiConfiguration();
    
            wifiConfig.SSID = String.format("\"%s\"", "Wifi name");
            wifiConfig.preSharedKey = String.format("\"%s\"", "Wifi password");
    
            WifiManager wifiManager=(WifiManager)getSystemService(WIFI_SERVICE);
            int netId = wifiManager.addNetwork(wifiConfig);
            wifiManager.disconnect();
            wifiManager.enableNetwork(netId, true);
            wifiManager.reconnect();
    

    And Also don't forget to include this code to your AndroidManifest.xml

    
    
    
    
    

提交回复
热议问题