Creating WiFi Network Configurations

To connect to a Wi-Fi network you need to create and register a configuration. Normally, your users would do this using the native Wi-Fi configuration settings, but there's no reason you can't expose the same functionality within your own applications, or for that matter replace the native Wi-Fi configuration Activity entirely.

Network configurations are stored as Wificonfiguration objects. The following is a non-exhaustive list of some of the public fields available for each Wi-Fi configuration:

> bssid The BSSID for an access point

> ssid The SSID for a particular network

> networkid A unique identifier used to identify this network configuration on the current device

> priority The network configuration's priority to use when ordering the list of potential access points to connect to

> status The current status of this network connection, which will be one of the following: WifiConfiguration.Status.ENABLED, WifiConfiguration.Status.DISABLED, or WifiConfiguration.Status.CURRENT

The configuration object also contains the supported authentication techniques, as well as the keys used previously to authenticate with this access point.

The addNetwork method lets you specify a new configuration to add to the current list; similarly, updateNetwork lets you update a network configuration by passing in a Wificonfiguration that's sparsely populated with a network ID and the values you want to change.

You can also use removeNetwork, passing in a network ID, to remove a configuration.

To persist any changes made to the network configurations, you must call saveConfiguration.


In this chapter you learned how to monitor and control some of the low-level communication hardware services available on Android devices.

The chapter included an introduction to Bluetooth management and communications mechanisms, a look at how to monitor and control Internet and network connectivity settings, and an introduction to the Wi-Fi manager — used to monitor and control the device's Wi-Fi connectivity and configurations.

In the next chapter you'll learn how to interact with the Sensor Manager to provide your applications access to the physical world. You will learn how to access the hardware sensors — particularly the compass and accelerometer — and how to monitor and interpret these sensors' values.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide

Post a comment