Android 檢測網絡與GPS是否可用

1.網絡是否鏈接(包括Wifi和移動網絡)
//是否有可用網絡 
    private boolean isNetworkConnected() { 
        ConnectivityManager cm =  
                (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); 
        NetworkInfo network = cm.getActiveNetworkInfo(); 
        if (network != null) { 
            return network.isAvailable(); 
        } 
        return false; 
    }  網絡

2.wifi是否可用
//Wifi是否可用 
    private boolean isWifiEnable() { 
        WifiManager wifiManager = (WifiManager) mContext 
                .getSystemService(Context.WIFI_SERVICE); 
        return wifiManager.isWifiEnabled(); 
    }  ide

3.GPS是否可用
//Gps是否可用 
    private boolean isGpsEnable() { 
        LocationManager locationManager =  
                ((LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE)); 
        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
    } get

相關文章
相關標籤/搜索