Connect to Wifi [without Internet] with a high pri

2020-07-24 06:43发布

I have a problem. I develop a android app, which should also connect to a wifi [without internet, just to controll a robot, webinterface: 10.10.0.1].

MY PROBLEM: If I connect to the robot wifi, Android prevents the connection and connect to my default home wlan.

What can I change to connect to robot wifi without problems?

My connection function:

public static void connectToWifi(String ssid, String pass){
    WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    WifiConfiguration conf = new WifiConfiguration();
    conf.SSID = "\"" + ssid + "\"";
    conf.preSharedKey = "\""+ pass +"\"";
    conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);


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

0条回答
登录 后发表回答