| Name the API which is used to manage all aspects of WIFI connectivity with syntax?
Name of WIFI API is WiFiManager which is used to manage all the aspects of WiFi connectivity. And to instantiate this class we used method name is getSystemService. And syntax is given below:-
WifiManager Wifiobjmain;
Wifiobjmain = (WifiManager) getSystemService(Context.WIFI_SERVICE);
And to get the scan list of wirless networks we need to register our broadcastReceiver. And to register we use registerReceiver method with argument of our receiver class object. And syntax for this is given below:-
class WifiScanReceiver extends BroadcastReceiver
{
public void onReceive(Context c, Intent intent)
{
}
}
WifiScanReceiver wifiRecieverobj = new WifiScanReceiver();
registerReceiver(wifiRecieverobj, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
And to start above scan we use startScan method of WifiManager class. And this method returns a list of ScanResult objects. And to access this object we use get method. ANd systax for that is given below:-
List< ScanResult> wifiScanList = mainWifiObj.getScanResults();
String data = wifiScanList.get(0).toString();
| | |