i am trying to develop an app that scans the existing WiFi signal surrounded my deceive and if specific WiFi signal is existed, the program will do specific instructions as follows in the program bellow :

 for (ScanResult result: results) {  
            int strength1 = info.getRssi ();
            float  strength_in_pre11=2*(strength1+100);
            float  Distance1 =30*(1-(strength_in_pre11/100));
tv = (TextView) findViewById (R.id.textView1);

        if (result.SSID.equals("WiFi1")) {
      String text="We are connecting to "+SSID+" Distance:"+Distance1+" " ;
            tv.setText (text);
        }

        else {
            String otherwifi1="The existing network is:\n\n";
     otherwifi1+=result.SSID+":"+result.level+"\n\n";
        otherwifi1+=result.SSID+":"+result.level+":"+Distance1+"\n";
        tv.setText (otherwifi1);
        }

    }

well , the if statement is not satisfied even though the router name that i put in the if statement (WiFi1) is existed , only else condition is satisfied ?! anyone can help

thank you

有帮助吗?

解决方案

Check what's the value of result.SSID :

System.out.println(result.SSID.toString());

if (result.SSID.toString().equals("WiFi1")) {
      String text="We are connecting to "+SSID+" Distance:"+Distance1+" " ;
      tv.setText (text);
    }

其他提示

Can you try and put a log or syso to see what the ssid is ? and whether it has whitespaces or quotes around the actual name?

i current did something similar and i had to change my if to the following as the ssids i encountered had quotes

if (result.SSID.equals('"' + "WiFi1" + '"'))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top