activeNetworkInfo.type is deprecated in API level 28

UPDATE The connectivityManager.activeNetworkInfo is also deprecated in API level 29 Now we need to use ConnectivityManager.NetworkCallback API or ConnectivityManager#getNetworkCapabilities or ConnectivityManager#getLinkProperties SAMPLE CODE USING ConnectivityManager#getNetworkCapabilities private fun isInternetAvailable(context: Context): Boolean { var result = false val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val networkCapabilities = connectivityManager.activeNetwork ?: return false val actNw … Read more

ConnectivityManager getNetworkInfo(int) deprecated

You can use: getActiveNetworkInfo(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null) { // connected to the internet if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { // connected to wifi } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { // connected to mobile data } } else { // not connected to the internet } … Read more

tech