Here is a very simple example how to prepare a mechanism for checking internet connection. It allows to detect if device has internet connection and of connection as well (Mobile or Wifi).
The example application has the following goals:
- Check if device has internet connection
- Detect connection type (Mobile or Wifi)
- Handle system event when internet connection has changed
- Example mostly based on the ConnectivityManager which allows get state of network connectivity
- Register the BroadcastReceiver on action:
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
for handle any change of connectivity