Networking
Many Android applications transfer data between the device and a server, or between devices. Like the battery state, applications may need to retrieve information about the network connections on the device. The ConnectivityManager
class provides APIs applications can call to have access to the network information. Android devices often have multiple data connections available:
- Bluetooth
- Ethernet
- Wi-Fi
- WiMAX
- Mobile (EDGE, UMTS, LTE)
Listing 7–6 shows how to retrieve information about the active connection as well as all the connections.
private void showNetworkInfoToast() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
// ...
Get Pro Android Apps Performance Optimization now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.