Sunday, February 16, 2014

About wifiManager.getConnectionInfo () and wifiManager.getScanResults () the use of


posts by programmer_wei on 2013-05-01 17:30:12 Edit
First explain:
wifiManager.getConnectionInfo () is used to obtain information currently wifi connection.
wifiManager.getScanResults () is used to get the phone to scan all wifi information.

Brother in a thread inside before placing wifiManager.getConnectionInfo () real-time access to information currently connected wifi signal strength, using a textview to display real-time changes in the signal strength, this is achieved, along with my principles or near the router, the textview signal strength will change.

But then I tried to wifiManager.getScanResults () side shows the signal strength of the current sweep out all changes in real-time wireless signal inside the thread, but found textview without any change in signal strength, and only when I re-entered after the program exits, signal strength display on the changes, meaning that the use of wifiManager.getScanResults (), the screen is not updated in real time, I do not know why this is.
 
private void obtainWifiInfo () {

/ / Display information about the current wifi connection (can be updated in real time)
WifiInfo info;
info = wifiManager.getConnectionInfo ();
if (info.getBSSID ()! = null) {
/ / Link signal strength
double strength = WifiManager.calculateSignalLevel (info.getRssi (), 1001);
textview1.setText ("strength:" + strength + "");
/ / Wifi source name
String ssid = info.getSSID ();
textview0.setText ("Name:" + ssid + "");
}



/ / Display the scanned information to all wifi (not real-time updates):
WifiManager wifiManager = (WifiManager) getSystemService (WIFI_SERVICE);
StringBuilder scanBuilder = new StringBuilder ();
List scanResults = wifiManager.getScanResults () ;/ / search to the list of devices
for (ScanResult scanResult: scanResults) {
scanBuilder.append ("\ n Device Name:" + scanResult.SSID
+ "\ N signal strength:" + wifiManager.calculateSignalLevel (scanResult.level, 1001) + "\ n");
}
textview3.setText (scanBuilder);
}



 
Thread t = new Thread (new Runnable ()
{
public void run ()
{

while (true)
{
runOnUiThread (new Runnable ()
{
public void run ()
{

obtainWifiInfo ();
}
});
try {
Thread.sleep (500);
} Catch (InterruptedException e) {
e.printStackTrace ();
}
}
}
});
t.start ();
}

<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
This really did not study
Reply:
wifiManager.getConnectionInfo () as if the words are,
So scanresult is past tense. Want to get all the hot spots of the signal must be taken one by one each of the current hot wifiinfo.
Reply:
reference to the second floor zxthello reply:
wifiManager.getConnectionInfo () If as now, then,
So scanresult is past tense. Want to get all the hot spots of the signal must be taken one by one each of the current hot wifiinfo.

If you take the current wifiinfo each hotspot, then you will need to have one by one for each hotspot to connect up again measured signal strength bar, as if not reality
Reply:
Because you want to start scanning, ah, in order to obtain the most current scanresult, does not scan the scan results Zehui update it
Reply:
WifiManager have started scanning interface, very, very long time, go and see your own
Reply:
Get real-time updates recently been searching nearby WIFI signal strength, tried many methods, do not know how to solve
Reply:
reference to the 6th floor haoge520 reply:
get real-time updates recently been searching nearby WIFI signal strength, tried many methods, do not know how to solve

Call startscan ()
Reply:
reference to the 7th floor programmer_wei reply:
Quote: references to the 6th floor haoge520 reply:

Get real-time updates recently been searching nearby WIFI signal strength, tried many methods, do not know how to solve

Call startscan ()


I have solved the first three days, and also call the hot new start scanning method you said, someone finally replies, thank you
Reply:
How did you solve it?
Reply:

Thread t = new Thread (new Runnable ()
{
public void run ()
{

while (true)
{
runOnUiThread (new Runnable ()
{
public void run ()
{

obtainWifiInfo ();
}
});
try {
Thread.sleep (500);
} Catch (InterruptedException e) {
e.printStackTrace ();
}
}
}
});
t.start ();
}

The code you write strange

No comments:

Post a Comment