Determine if the network is connected
public static Boolean isnetworkenabled (context context) {
int Status=-1//Set the default connection status to-1
Connectivitymanager Connectivitymanager = (connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
Networkinfo networkinfo = Connectivitymanager.getactivenetworkinfo ();
if (networkinfo! = null && networkinfo.isconnected ()) { //networkinfo.isconnected () determines whether the network is connected
Switch (Networkinfo.gettype ()) {
Case Connectivitymanager.type_mobile: {
Status = 0;// mobile data connection. when active, all data traffic. The interface that will use this default network type
Break
}
Case Connectivitymanager.type_wifi: {
status = 1;// wireless data connection. when active, all data traffic
Break
}
Default: {
status = 2;// One mms-specific mobile data connection. You can use this network type
Break
}
}
}
if (status = =-1) {
return false;
} else {
return true;
}
}
Determine if the GPS is connected
public static Boolean Isgpsopen (context context) {
Locationmanager Locationmanager = (locationmanager) context
. Getsystemservice (Context.location_service);
Boolean GPS = Locationmanager
. isproviderenabled (Locationmanager.gps_provider);
if (GPS)
{
return true;
}
return false;
}
Determine if the network is connected and determine if the GPS is connected