I am using the following code but it does not show me the BSSID in the list of Wifi networks,
public class MainActivity extends AppCompatActivity {
ListView lv;
WifiManager wifi;
String wifis[];
WifiScanReceiver wifiReciever;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView) findViewById(R.id.listview);
wifi=(WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiReciever = new WifiScanReceiver();
wifi.startScan();
Button btn=(Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
wifi.startScan();
Toast notificacion=Toast.makeText(MainActivity.this,"Actualizacion de parametros",Toast.LENGTH_SHORT);
notificacion.show();
}
});
}
protected void onPause(){
unregisterReceiver(wifiReciever);
super.onPause();
}
protected void onResume(){
registerReceiver(wifiReciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
super.onResume();
}
private class WifiScanReceiver extends BroadcastReceiver {
public void onReceive(Context c, Intent intent){
WifiInfo nombre1 = wifi.getConnectionInfo();
TextView name = (TextView) findViewById(R.id.textView);
name.setText(nombre1.getSSID());
List<ScanResult> wifiScanList = wifi.getScanResults();
wifis = new String[wifiScanList.size()];
for (int i=0; i<wifiScanList.size(); i++){
wifis[i]=((wifiScanList.get(i)).toString());
}
lv.setAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, wifis));
}
}
It only shows me the list from 'capabilities' but the name of the network does not show it. Only using:
WifiInfo nombre1 = wifi.getConnectionInfo();
TextView name = (TextView) findViewById(R.id.textView);
name.setText(nombre1.getSSID());
Is that I can show in a TextView the name of the Wi-Fi Network but if I'm not connected to any network it does not show me the name.
On the other hand, the permissions that you declare in 'Android Manifest' are:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>