开发者

Quickest Possible Wifi Access Point Switching

开发者 https://www.devze.com 2023-03-29 00:16 出处:网络
I am developing an audio communication application which requires that an android phone quickly switch from one WiFi network to another. Currently, my code takes anywhere from 7 to 15 seconds switchin

I am developing an audio communication application which requires that an android phone quickly switch from one WiFi network to another. Currently, my code takes anywhere from 7 to 15 seconds switching WiFi networks that it already knows exist in the environment and are pre-configured. Is it possible to accelerate this time to switch. Must I live with buffering 15+ seconds of audio so that when the user roams from one WiFi network to the next, they won't hear any pauses?

 private void SwitchWifi(){

    int myBestNetworkStrength = -60;
    int myBestNetworkID = -1;
    List<WifiConfiguration> currentConfig = myManager.getConfiguredNetworks();
    if(myManager.startScan()){
        if(myNetworks==null){
            Initialize();
        }
        List<ScanResult> wifiList = myManager.getScanResults();
        for(int i = 开发者_如何学JAVA0; i < wifiList.size(); i++){
            for(int j = 0; j < myNetworks.size(); j++){
                if(wifiList.get(i).SSID.matches(myNetworks.get(j).mySSID)){
                    if(myBestNetworkStrength < wifiList.get(i).level){
                        for(int k = 0; k < currentConfig.size(); k++){
                            DebugScreen.AddLog("WIFIswitch", "k = " + currentConfig.get(k).SSID);
                            if(currentConfig.get(k).SSID.matches("\"" + wifiList.get(i).SSID+ "\"")){
                                myBestNetworkID = k;
                                myBestNetworkStrength = wifiList.get(i).level;
                            }
                        }
                    }
                }
            }
        }
    }//
    DebugScreen.AddLog("WIFIswitch", "Best network strength is " + Integer.toString(myBestNetworkStrength) + " with network #" + Integer.toString(myBestNetworkID) );
    if(myBestNetworkID != -1){
        MailService.is_Waiting_For_New_Connection = true;
        while(!MailService.has_Entered_Pause_Loop){
            if(!isAlive())
                return;
        }
        myManager.disconnect();
        myManager.enableNetwork(myBestNetworkID, true);
        myManager.reconnect();
        MailService.is_Waiting_For_New_Connection = false;
    }
}


Maybe you could have an object that extends Observable (or implements a custom listener) that checks regularly (in a thread ?) what's the best network. When you detect that the current network is not the best anymore, you just notify the observers (or fire up the listener) and actually enable/reconnect to the new network.

So detecting what's the best network will always last 7 to 15s, but as it is done in background, switching from a network to another will be almost immediatly effective.

0

精彩评论

暂无评论...
验证码 换一张
取 消