Android give facility to access the Wifi Network in your Application. You can access nearly every information of the connection.
Android have WifiManager API to handle all Wifi Connectivity.You can use it like this:
WifiManager wifiManagerObject;
WifiScanReceiver connectionReciever;
wifiManagerObject = (WifiManager) getSystemService(Context.WIFI_SERVICE);
and then initialiate the Receiver and start scan by startscan()
connectionReceiver = new WifiScanReceiver();
wifiManagerObject.startScan();
and Register the BroadcastReceiver
protected void onPause() {
unregisterReceiver(connectionReciever);
super.onPause();
}
protected void onResume() {
registerReceiver(connectionReciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
super.onResume();
}
And to list out the networks, We need to use BroadCastReceiver
String arrayWifi[];
private class ConnectionReceiver extends BroadcastReceiver{
public void onReceive(Context _context, Intent _intent) {
List listWifi = wifiManagerObject.getScanResults();
wifis = new String[listWifi.size()];
for(int i = 0; i < listWifi.size(); i++){
arrayWifi[i] = ((listWifi.get(i)).toString());
}
//set adapter to list out all wifi connections.
}
}
0 Comment(s)