最佳答案
I want to use the Connectivity manager which provide the method activeNetworkInfo.type for checking the type of network in Android. This method was deprecated in API level 28. so what is the solution to check network type in API 28. my code is :
/**
* Check Wi Fi connectivity
*/
fun isWiFiConnected(context: Context): Boolean {
val connManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
return connManager.activeNetworkInfo.type == ConnectivityManager.TYPE_WIFI
}
My Gradle is like :
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
}