[Kotlin] Check Internet connection is available – Android

In every application, it is now mandatory to have Internet connectivity either to serve information from server or sending information to server. But it is very much important to check whether network connection is available or not before retrieving server.

To do so, we have only 3 lines of code which give status of current connectivity.

First, we require a context and from there we can take System service of “CONNECTIVITY_SERVICE”.
Then we will fetch network information from that object and finally will check if Internet is available or not. Use this boolean object isConnected in your condition and perform necessary action if connection available.

It’s very easy!!

Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on Tumblr0Email this to someone