判断 Wifi 是否启用
/**
* 判断 Wifi 是否启用
*
* @param context context
* @return true/false
*/
@kotlin.jvm.JvmStatic
fun wifiIsEnable(context: Context): Boolean {
val connectivityManager: ConnectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val wifi_state = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).state
if (wifi_state == NetworkInfo.State.CONNECTED || wifi_state == NetworkInfo.State.CONNECTING) {
return true
}
return false
}
判断 GPRS 是否启用
/**
* 判断 GPRS 是否启用
*
* @param context context
* @return true/false
*/
@kotlin.jvm.JvmStatic
fun gprsIsEnable(context: Context): Boolean {
val connectivityManager: ConnectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val gprs_state = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).state
if (gprs_state == NetworkInfo.State.CONNECTED || gprs_state == NetworkInfo.State.CONNECTING) {
return true
}
return false
}