SoFunction
Updated on 2025-03-01

How to check the network status and network type of mobile phones on Android

This article describes the method of Android checking the network status and network type of mobile phones. Share it for your reference. The specific analysis is as follows:

//judge network status is connecting or not
 public static boolean checkNetworkConnected(Context context) { 
 if (null!=context) { 
 ConnectivityManager connectivityManager = (ConnectivityManager) context
 .getSystemService(Context.CONNECTIVITY_SERVICE); 
 NetworkInfo networkInfo = ();
 if (null!=networkInfo) { 
  return (); 
  } 
 } 
  return false; 
 } 
 //judge Wifi status is connecting or not
 public static boolean checkWifiStatus(Context context) { 
 ConnectivityManager connectivityManager = (ConnectivityManager) context 
 .getSystemService(Context.CONNECTIVITY_SERVICE); 
 NetworkInfo networkInfo = (); 
 if (null!=networkInfo 
 && () == ConnectivityManager.TYPE_WIFI) { 
 return true; 
  } 
 return false; 
 } 
 //judge 3G status is connecting or not
 public static boolean check3GStatus(Context context) { 
 ConnectivityManager connectivityManager = (ConnectivityManager) context 
 .getSystemService(Context.CONNECTIVITY_SERVICE); 
 NetworkInfo networkInfo = (); 
 if (null!=networkInfo 
 && () == ConnectivityManager.TYPE_MOBILE) { 
 return true; 
  }
 return false; 
 }

I hope this article will be helpful to everyone's Android programming design.