The android.net package provides two very useful classes for incorporating WiFi into applications, the ConnectivityManager and the wifi.WifiManager. The first of these manages and monitors the network connection and the latter is the primary class for WiFi connectivity.
In this example we will use these classes to query the network and WiFi state of a device.
WiFi is not available on Android Virtual Devices so to test this demonstration you will need a handset with WiFi enabled. Next, start up a new project in Eclipse.
WiFi connectivity requires the following two permissions to be declared in the Manifest:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
We will use three TextViews to display our information. Include these in the
res/layout/main.xml
file and give then the following resource IDs:android:id="@+id/network_text" android:id...