download:Delve deeper into the Vue3+TypeScript technology stack – a new lesson on CoderWhy

package com.chengxinet.bobo.utils;

import android.content.Context;

import android.net.ConnectivityManager;

import android.net.NetworkInfo;

import android.telephony.TelephonyManager;

/ * *

  • Created by Administrator on 2016/1/7.

    */

public class NetworkUtils {

public static boolean isNetworkAvailable(Context c) { Context context = c.getApplicationContext(); ConnectivityManager = (ConnectivityManager) ConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return false; } else {/ / NetworkInfo for NetworkInfo object [] NetworkInfo = connectivityManager. GetAllNetworkInfo (); if (networkInfo ! = null && networkInfo.length > 0) { for (NetworkInfo aNetworkInfo : networkInfo) {

/ / System. Out. Println (I + “state = = = = = =” + networkInfo [I] getState ()); / / System. Out. Println (I + “type = = = = = =” + networkInfo [I] getTypeName ());

/ / determine whether the current network status for connection State if (aNetworkInfo. GetState () = = NetworkInfo. State. The CONNECTED) {return true; } } } } return false; } /** * Check if WiFi is enabled * @param context * @return */ public static Boolean isWifiEnabled(context context) { ConnectivityManager mgrConn = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager mgrTel = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); return ((mgrConn.getActiveNetworkInfo() ! = null && mgrConn .getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel .getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS); Public static Boolean is3rd(Context Context) {ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkINfo = cm.getActiveNetworkInfo(); if (networkINfo ! = null && networkINfo.getType() == ConnectivityManager.TYPE_MOBILE) { return true; } return false; } /** * public static Boolean isWiFi (Context Context) {ConnectivityManager * @Param Context * @Return */ public static Boolean isWiFi (Context Context) {ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkINfo = cm.getActiveNetworkInfo(); if (networkINfo ! = null && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } return false; }

}