Chapter 19. System and Device Control
19.1. Introduction: System and Device Control
Android provides a good compromise between the needs of the carriers for control and the needs of developers for device access. This chapter looks at some of the informational and control APIs that are publicly available to the Android developer to explore and control the extensive hardware facilities provided by the system, and to deal with the wide range of hardware it runs on, from 2-inch cell phones to 10-inch tablets and netbooks.
19.2. Accessing Phone Network/Connectivity Information
You want to find information about the device’s current network connectivity.
You can determine whether your phone is connected to the network,
its type of connection, and whether your phone is in roaming territory,
ConnectivityManager and a
Often you need to know whether the device you are running on can
connect to the Internet at the moment, and, since roaming can be
expensive, it is also very useful if you can tell the user whether he is
roaming (the user who is truly worried about this will disable data
roaming using the Settings application). To do this and more we can use
NetworkInfo class in the
android.net package, as in Example 19-1.
ConnectivityManager connManager = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = connManager.getActiveNetworkInfo(); ...