I am working on a live project. and when user click on the app. the welcome screen appears(there is a webview on that screen). and if the internet is not connected then the
An Updated Kotlin and Android 29 Version (getNetworkInfo is deprecated in SDK 29) on how to check for internet connection, works for minSDK >= 23 :
fun hasInternet(): Boolean {
val connectivityManager = appContainer.contextProvider.currentAppContext()
.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val network = connectivityManager.activeNetwork
val capabilities = connectivityManager.getNetworkCapabilities(network)
var hasInternet = false
capabilities?.let {
hasInternet = it.hasCapability(NET_CAPABILITY_INTERNET)
}
return hasInternet
}