// 检测网络
public static boolean checkNet(Activity act) {
ConnectivityManager manager = (ConnectivityManager) act
.getApplicationContext().getSystemService(
Context.CONNECTIVITY_SERVICE);
if (manager == null) {
return false;
}
NetworkInfo networkinfo = manager.getActiveNetworkInfo();
if (networkinfo == null || !networkinfo.isAvailable()) {
return false;
}
return true;
}
public static boolean checkNet_(Context context) {
ConnectivityManager mConnectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
// 获取代表联网状态的NetWorkInfo对象
NetworkInfo info = mConnectivity.getActiveNetworkInfo();
if (info == null) {
return false;
}
// info.isAvailable() 获取当前的网络连接是否可用
if (!info.isAvailable() || !mConnectivity.getBackgroundDataSetting()) {// 有网络的情况
// 没有网络直接返回false
return false;
} else {
State wifiState = mConnectivity.getNetworkInfo(
ConnectivityManager.TYPE_WIFI).getState();
State gprsState = mConnectivity.getNetworkInfo(
ConnectivityManager.TYPE_MOBILE).getState();
boolean wifi = wifiState == State.CONNECTED;
boolean gprs = gprsState == State.CONNECTED;
return wifi || gprs;
}
}
// 获取mac地址
public static String getLocalMacAddress(Context context) {
WifiManager wifi = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
return info.getMacAddress();
}