List of available Wifi devices

android

Solution

You can get the available WIFI Scan results by

List<ScanResult> mScanResults = mWifiManager.getScanResults();

Then iterating over `mScanResults` and getting SSID using `results.SSID`. Also if you are interested to get the best network you can use `WifiManager.compareSignalLevel(int rssiA, int rssiB)` for comparing two networks.

ScanResult bestResult = null;
for(ScanResult results : mScanResults){
   Log.d("result",results.SSID);
   if(bestResult == null || WifiManager.compareSignalLevel(bestResult.level,
                                                         results.level) < 0){
      bestResult = results;
   }
}
String message = String.format("%s networks found. %s is the strongest.", 
                                           mScanResults.size(), bestResult.SSID);
Log.d("best network",message);

You can download complete demo from my `repository`.

Problem

I want to display list of Available Wifi devices. This is my code, I do not understand what mistake is here: ``` wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifi.isWifiEnabled() == false) { Toast.makeText(getApplicationContext(), "wifi is disabled..making it enabled",Toast.LENGTH_LONG).show(); wifi.setWifiEnabled(true); } String[] str1 = null; ArrayAdapter<String>adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android.R.id.text1,str1); lv.setAdapter(adapter); WifiInfo info = wifi.getConnectionInfo(); textStatus.append("\n\nWiFi Status: " + info.toString()); boolean b=wifi.isWifiEnabled(); if(b){ wifi.setWifiEnabled(false); Toast.makeText(getApplicationContext(), "Yes", Toast.LENGTH_SHORT).show(); enter code here ``` This is my code, I want to get Wifi enabled device properties specifically in Android by programmatically. How can I get that? ``` public void onReceive(Context c, Intent intent) { results = wifi.getScanResults(); size = results.size(); int i = 0; str1 = new String[size]; for (ScanResult result : results){ str1[i] = result.SSID + " " + result.level; i++; } ```

Original source