Merge pull request #2052 from 821938089/fix-webdav-network-detect

fix webdav network detect bug
pull/2054/head
kunfei 2 years ago committed by GitHub
commit 842c3b44a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt

@ -27,22 +27,24 @@ object NetworkUtils {
if (Build.VERSION.SDK_INT < 23) { if (Build.VERSION.SDK_INT < 23) {
val mWiFiNetworkInfo = connectivityManager.activeNetworkInfo val mWiFiNetworkInfo = connectivityManager.activeNetworkInfo
if (mWiFiNetworkInfo != null) { if (mWiFiNetworkInfo != null) {
//移动数据 // WIFI
return if (mWiFiNetworkInfo.type == ConnectivityManager.TYPE_WIFI) { return mWiFiNetworkInfo.type == ConnectivityManager.TYPE_WIFI ||
//WIFI // 移动数据
true mWiFiNetworkInfo.type == ConnectivityManager.TYPE_MOBILE ||
} else mWiFiNetworkInfo.type == ConnectivityManager.TYPE_MOBILE // 以太网
mWiFiNetworkInfo.type == ConnectivityManager.TYPE_ETHERNET
} }
} else { } else {
val network = connectivityManager.activeNetwork val network = connectivityManager.activeNetwork
if (network != null) { if (network != null) {
val nc = connectivityManager.getNetworkCapabilities(network) val nc = connectivityManager.getNetworkCapabilities(network)
if (nc != null) { if (nc != null) {
//移动数据 // WIFI
return if (nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { return nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) ||
//WIFI // 移动数据
true nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) ||
} else nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) // 以太网
nc.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)
} }
} }
} }

Loading…
Cancel
Save