/**
* Network Status WiFi Mobile
*
* @author jiangbing
*
*/
public class Networkutils {
/**
* Determine if the current network connection (valid connection) is not divided into WiFi mobile
*/
public static Boolean isconnectdeavailable (context context) {
try {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo networkinfo = Manager.getactivenetworkinfo ();
if (networkinfo! = null && networkinfo.isconnected ()) {
if (networkinfo.getstate () = = NetworkInfo.State.CONNECTED) {
return true;
}
}
}
} catch (Exception e) {
return false;
}
return false;
}
/**
* Determine if the current WiFi network
*/
public static Boolean ISWIFICONNECTDE (context context) {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo Networkinfo = Manager
. Getnetworkinfo (Connectivitymanager.type_wifi);
if (networkinfo! = null && networkinfo.isconnected ()) {
return true;
}
}
return false;
}
/**
* Determine whether the current WiFi network (whether the connection is valid)
*/
public static Boolean iswificonnectdeavailable (context context) {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo Networkinfo = Manager
. Getnetworkinfo (Connectivitymanager.type_wifi);
if (networkinfo! = null && networkinfo.isconnected ()) {
if (networkinfo.getstate () = = NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
/**
* Determine if the current network is moving the network
*
* @param context
* @return Boolean
*/
public static Boolean ISMOBILECONNECTDE (context context) {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo Networkinfo = Manager
. Getnetworkinfo (Connectivitymanager.type_mobile);
if (networkinfo! = null && networkinfo.isconnected ()) {
return true;
}
}
return false;
}
/**
* Determine if the current network is moving the network (whether the connection is valid)
*
* @param context
* @return Boolean
*/
public static Boolean ismobileconnectdeavailable (context context) {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo Networkinfo = Manager
. Getnetworkinfo (Connectivitymanager.type_mobile);
if (networkinfo! = null && networkinfo.isconnected ()) {
if (networkinfo.getstate () = = NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
/**
* Open the Network Settings screen
*/
public static void opensetting (activity activity) {
Intent Intent = new Intent ("/");
ComponentName cm = new ComponentName ("Com.android.settings",
"Com.android.settings.WirelessSettings");
Intent.setcomponent (CM);
Intent.setaction ("Android.intent.action.VIEW");
Activity.startactivityforresult (Intent, 0);
}
/**
* Whether the GPS is turned on
*
* @param context
* @return
*/
public static Boolean isgpsenabled (context context) {
Locationmanager Locationmanager = ((Locationmanager) context
. Getsystemservice (Context.location_service));
list<string> accessibleproviders = Locationmanager.getproviders (true);
return accessibleproviders! = null && accessibleproviders.size () > 0;
}
}
Android network status judging WiFi mobile