| | |
| | | } |
| | | |
| | | public static boolean isNetworkAvailable(Context context) { |
| | | ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | ConnectivityManager mgr = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | NetworkInfo[] info = mgr.getAllNetworkInfo(); |
| | | if (info != null) { |
| | | for (int i = 0; i < info.length; i++) { |
| | |
| | | |
| | | public static boolean isNetworkConnected(Context context) { |
| | | if (context != null) { |
| | | ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); |
| | | if (mNetworkInfo != null) { |
| | | return mNetworkInfo.isAvailable(); |
| | |
| | | |
| | | public static boolean isWifiConnected(Context context) { |
| | | if (context != null) { |
| | | ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); |
| | | if (mWiFiNetworkInfo != null) { |
| | | return mWiFiNetworkInfo.isAvailable(); |
| | |
| | | |
| | | public static boolean isMobileConnected(Context context) { |
| | | if (context != null) { |
| | | ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); |
| | | if (mMobileNetworkInfo != null) { |
| | | return mMobileNetworkInfo.isAvailable(); |
| | |
| | | |
| | | public static int getConnectedType(Context context) { |
| | | if (context != null) { |
| | | ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); |
| | | if (mNetworkInfo != null && mNetworkInfo.isAvailable()) { |
| | | return mNetworkInfo.getType(); |
| | |
| | | } |
| | | |
| | | public static NetType getAPNType(Context context) { |
| | | ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | ConnectivityManager connMgr = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); |
| | | NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); |
| | | if (networkInfo == null) { |
| | | return NetType.NONE; |