WHAT'S IN THIS CHAPTER?
> Managing Bluetooth devices
> Discovering remote Bluetooth devices
> Managing discovery mode
> Communicating over Bluetooth
> Monitoring Internet connectivity
> Obeying user preferences for background data transfer
> Monitoring Wi-Fi and network details
> Configuring networks and Wi-Fi configurations
> Scanning for Wi-Fi access points
In this chapter you'll continue to explore Android's low-level communications APIs by examining the Bluetooth, network, and Wi-Fi packages.
Android offers APIs to manage and monitor your Bluetooth device settings, to control discoverability, to discover nearby Bluetooth devices, and to use Bluetooth as a proximity-based peer-to-peer transport layer for your applications.
A full network and Wi-Fi package is also available. Using these APIs you can scan for hotspots, create and modify Wi-Fi configuration settings, monitor your Internet connectivity, and control and monitor Internet settings and preferences.
In this section you'll learn how to interact with the local Bluetooth device and communicate with remote devices on nearby phones.
Using Bluetooth you can search for, and connect to, other devices within range. By initiating a communications link using Bluetooth Sockets you can then transmit and receive streams of data between devices from within your applications.
The Bluetooth libraries have been available in Android only since Android version 2.0 (SDK API level 5). It's also important to remember that not all Android devices will necessarily include Bluetooth hardware.
Bluetooth is a communications protocol designed for short-range, low-bandwidth peer-to-peer communications. As of Android 2.1, only encrypted communication is supported, meaning you can only form connections between paired devices. In Android, Bluetooth devices and connections are handled by the following classes:
> BluetoothAdapter The Bluetooth Adapter represents the local Bluetooth device — that is, the Android device on which your application is running.
> BluetoothDevice Each remote device with which you wish to communicate is represented as a BluetoothDevice.
> BluetoothSocket Call createRfcommSocketToServiceRecordon a remote Bluetooth Device object to create a Bluetooth Socket that will let you make a connection request to the remote device, and then initiate communications.
> BluetoothServerSocket By creating a Bluetooth Server Socket (using the listenUsingRfcommWithServiceRecord method) on your local Bluetooth Adapter, you can listen for incoming connection requests from Bluetooth Sockets on remote devices.
Was this article helpful?
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.