Let’s Start it :)
- Create a Function like isNetworkAvailbale to check internet connection
and faction’s return type will be Boolean.
2. A variable like conManager, Where we will declare Connectivity Manager.
3. Also a another variable like internetInfo , To Know internet information.
4. When returning this Function , Where we will check internetInfo not be null and internet is Connected or Not .
fun isNetworkAvailbale():Boolean{
val conManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val internetInfo =conManager.activeNetworkInfo
return internetInfo!=null && internetInfo.isConnected
}
Finally We can use this Function [isNetworkAvailbale()] , Where we want to check our internet connecton.
Hope it will work .
Thanks