startScan () returns immediately. The availability of the results is made known later by means of an asynchronous event sent on completion of the scan.
So, you either need to wait 10 seconds or so after startScan or wait till you get the event that the scan has completed. IOW, you are calling wifi.getScanResults() before it has time to find anything. On Friday, August 10, 2012 3:53:39 AM UTC-5, Meena Rengarajan wrote: > > Here , i wanna display list of Available Wifi devices .. > This is my code please anyone help me , i do not understand what mistake > is here ? > > Please anybody help me here , i wanna display list of Available Wifi > devices, i am very new to this Technology .. > > 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); > //lv.setAdapter(this.adapter); > WifiInfo info = wifi.getConnectionInfo(); > textStatus.append("\n\nWiFi Status: " + info.toString()); > // wifiConfig=new WifiConfiguration(); > // wifiConfig.status=WifiConfiguration.Status.ENABLED; > boolean b=wifi.isWifiEnabled(); > if(b){ > wifi.setWifiEnabled(false); > Toast.makeText(getApplicationContext(), "Yes", Toast.LENGTH_SHORT).show(); > } > > else{ > wifi.setWifiEnabled(true); > Toast.makeText(getApplicationContext(), "No", Toast.LENGTH_SHORT).show(); > } > > > > wifi.startScan(); > List<ScanResult> results = wifi.getScanResults(); > for (ScanResult result : results) { > Toast.makeText(this, result.SSID + " " + > result.level,Toast.LENGTH_SHORT).show(); > List<WifiConfiguration> configs = wifi.getConfiguredNetworks(); > for (WifiConfiguration config : configs) { > textStatus.append("\n\n" + config.toString()); > } > > if (receiver == null) > //receiver= new WiFiScanReceiver(this); > > registerReceiver(receiver, new IntentFilter( > WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); > Log.d(TAG, "onCreate()"); > } > } > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en