Monday, January 11, 2016

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


This post last edited by the programmer_wei on 2013-05-01 17:30:12
First explain:
wifiManager.getConnectionInfo () is used to get information currently wifi connection.
wifiManager.getScanResults () is used to obtain the phone scanned all wifi information.

Before brother in a thread placed inside wifiManager.getConnectionInfo () real-time access to information wifi signal strength of the current connection, with a real-time display textview to change signal strength, this is realized, with my principles or near the router, the textview The signal strength will change.

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

// Display information on the current wifi connection (real-time updates)
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 all wifi (not real-time updates):
WifiManager wifiManager = (WifiManager) getSystemService (WIFI_SERVICE);
StringBuilder scanBuilder = new StringBuilder ();
List & lt; ScanResult & gt; scanResults = wifiManager.getScanResults (); // searched device list
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 ();
}


Reply:
This really did not study
Reply:
wifiManager.getConnectionInfo () If as now, then,
So scanresult is past tense. I want to get all the hot spots of the signal must be taken one by one for each hotspot current wifiinfo.
Reply:
quote the second floor zxthello reply:
wifiManager.getConnectionInfo () If as now, then,
So scanresult is past tense. I want to get all the hot spots of the signal must be taken one by one for each hotspot current wifiinfo.

If you take each of the hotspots of wifiinfo then you will need for each hot spot to connect up one by one measured signal strength bar again, as if not reality
Reply:
Because you want to start scanning, ah, in order to obtain the most current scanresult, do not scan the scan results Zehui update it
Reply:
WifiManager have started scanning interface incredibly long time, you go and see
Reply:
Has recently been close to get real-time updates search WIFI signal strength, I tried many ways, do not know how to solve
Reply:
quote, 6th Floor haoge520 reply:
has recently been close to get real-time updates search WIFI signal strength, tried many ways, do not know how to solve

Call startscan ()
Reply:
quote 7th floor programmer_wei reply:
Quote: quote, 6th Floor haoge520 reply:

Has recently been close to get real-time updates search WIFI signal strength, I tried many ways, do not know how to solve

Call startscan ()


Three days ago I have resolved, but also call a hot new start scanning method you said, finally someone 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 ();
}

This code you write strange
Reply:
quote 8th floor haoge520 reply:
Quote: quote, 7th floor programmer_wei reply:

Quote: quote, 6th Floor haoge520 reply:

Has recently been close to get real-time updates search WIFI signal strength, I tried many ways, do not know how to solve

Call startscan ()


Three days ago I have resolved, but also call a hot new start scanning method you said, finally someone replies, thank you

The landlord, you just (before) in getScanResults added the startscan () you can update it? Why do I still will not. . . Seeking solutions
Reply:
The landlord saw me: I saw the landlord: The landlord saw me: I saw the landlord: The landlord saw me: I saw the landlord: The landlord saw me: I saw the landlord: The landlord saw me:


Will the landlord to solve specific method remember what I also hear of Unable to refresh content problem like you ~~~

Reply:
The landlord saw me: I saw the landlord: The landlord saw me: I saw the landlord: The landlord saw me: I saw the landlord: The landlord saw me: I saw the landlord: The landlord saw me:


Will the landlord to solve specific method remember what I also hear of the problem can not refresh the contents like you ~~~

My mail is 504932345@qq.com have a copy of the source code can do, to thank the landlord ~
Reply:
A source with the demand, beg the landlord a copy of the source code, together with the research. Thank you. I QQ-mail: 992313008@qq.com
Reply:
quote 7th floor programmer_wei reply:
Quote: quote, 6th Floor haoge520 reply:

Has recently been close to get real-time updates search WIFI signal strength, I tried many ways, do not know how to solve

Call startscan ()


I was the problem, looked great God say changed the code, it really can. Add

WifiManager wifiManager = (WifiManager) getSystemService (WIFI_SERVICE);
wifiManager.startScan (); // must start the scan only after detection of a change! !
List & lt; ScanResult & gt; results = wifiManager.getScanResults ();
Reply:
Learn, thanks for sharing.

No comments:

Post a Comment