use of android.net.NetworkInfo in project FastDev4Android by jiangqqlmj.
the class JudgeNetWorker method getAPNType.
/**
* @author jiangqq
* 获取当前的网络状态 -1:没有网络 1:WIFI网络 2:wap网络 3:net网络
* @param context
* @return
*/
public static int getAPNType(Context context) {
int netType = -1;
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_MOBILE) {
Log.e("networkInfo.getExtraInfo()", "networkInfo.getExtraInfo() is " + networkInfo.getExtraInfo());
if (networkInfo.getExtraInfo().toLowerCase().equals("cmnet")) {
netType = CMNET;
} else {
netType = CMWAP;
}
} else if (nType == ConnectivityManager.TYPE_WIFI) {
netType = WIFI;
}
return netType;
}
use of android.net.NetworkInfo in project FastDev4Android by jiangqqlmj.
the class JudgeNetWorker method checkConnectionOk.
public static boolean checkConnectionOk(Context context) {
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
return false;
}
return true;
}
use of android.net.NetworkInfo in project FastDev4Android by jiangqqlmj.
the class StrUtils method getAPNType.
public static int getAPNType(Context context) {
int netType = -1;
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_MOBILE) {
Log.e("networkInfo.getExtraInfo()", "networkInfo.getExtraInfo() is " + networkInfo.getExtraInfo());
if (networkInfo.getExtraInfo().toLowerCase().equals("cmnet")) {
netType = CMNET;
} else {
netType = CMWAP;
}
} else if (nType == ConnectivityManager.TYPE_WIFI) {
netType = WIFI;
}
return netType;
}
use of android.net.NetworkInfo in project Talon-for-Twitter by klinker24.
the class Utils method hasInternetConnection.
public static boolean hasInternetConnection(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
return isConnected;
}
use of android.net.NetworkInfo in project Android-Developers-Samples by johnjohndoe.
the class MainActivity method checkNetworkConnection.
/**
* Check whether the device is connected, and if so, whether the connection
* is wifi or mobile (it could be something else).
*/
private void checkNetworkConnection() {
// BEGIN_INCLUDE(connect)
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
if (activeInfo != null && activeInfo.isConnected()) {
wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
if (wifiConnected) {
Log.i(TAG, getString(R.string.wifi_connection));
} else if (mobileConnected) {
Log.i(TAG, getString(R.string.mobile_connection));
}
} else {
Log.i(TAG, getString(R.string.no_wifi_or_mobile));
}
// END_INCLUDE(connect)
}
Aggregations