Pages

Android allows applications to access to view the access the state of
the wirless connections at very low level. Application can access
almost all the information of a wifi connection.
The information that an application can access includes connected
network's link speed,IP address, negotiation state, other networks
information. Applications can also scan, add, save, terminate and
initiate Wi-Fi connections.
Android provides WifiManager API to manage all aspects of WIFI connectivity. We can instantiate this class by calling getSystemService method. Its syntax is given below:

In order to scan a list of wireless networks, you also need to register your BroadcastReceiver. It can be registered using registerReceiver method with argument of your reciever class object. Its sytanx is given below:

The wifi scan can be start by calling the startScan method of the WifiManager class. This method returns a list of ScanResult objects. You can access any object by calling the get method of list. Its syntax is given below:

isWifiEnabled()
This method return whether Wi-Fi is enabled or disabled.

7

setWifiEnabled(boolean enabled)
This method enable or disable Wi-Fi.

8

updateNetwork(WifiConfiguration config)
This method update the network description of an existing configured network.

Example

Here is an example demonstrating the use of WIFI. It creates a basic
application that scans a list of wirless networks and populate them in a
list view.
To experiment with this example , you need to run this on an actual device on which wifi is turned on.

Steps

Description

1

You will use Eclipse IDE to create an Android
application and name it as WIFI under a package com.example.wifi. While
creating this project, make sure you Target SDK and Compile With at the
latest version of Android SDK to use higher levels of APIs.

2

Modify src/MainActivity.java file to add WebView code.

3

Modify the res/layout/activity_main to add respective XML components

4

Modify the AndroidManifest.xml to add the necessary permissions

5

Run the application and choose a running android device and install the application on it and verify the results.

Following is the content of the modifed main activity file src/com.example.wifi/MainActivity.java.

Let's try to run your WIFI application. I assume you have connected
your actual Android Mobile device with your computer. To run the app
from Eclipse, open one of your project's activity files and click Run
icon from the toolbar. Before starting your application, Eclipse will
display following window to select an option where you want to run your
Android application.
Select your mobile device as an option and then check your mobile
device which will display your mobile screen filled with wireless
networks around you. It is shown below:
Note the information that has been returned to you. It contains much information about each of the wireless network detected.