Home » Android » Determine whether you have an internet connection / Monitor Network Connectivity in Android

Determine whether you have an internet connection / Monitor Network Connectivity in Android

This post details about the code required to implement to check if you have an internet connection or whether you are connected to active network and what is the type of network such as WiFi or Ethernet so that you can perform network dependent tasks with assured success or show failure cases to the user if network is not connected or gets disconnected in runtime.

Note: getActiveNetworkInfo() was deprecated in Android 10. Use NetworkCallbacks instead for apps that target Android 10 (API level 29) and higher.

You can also use following code as reference to do additional check and identify type of network as well as IP Address of the device.

Check Network Type if its Stable network [ Ref. MediaResourceGetter.java from Samsung github ]

Check Local Network IP Address [ Ref. oracle docs]

Reference


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment