Search in sources :

Example 26 with ConnectivityManager

use of android.net.ConnectivityManager in project Signal-Android by WhisperSystems.

the class OutgoingLegacyMmsConnection method isConnectionPossible.

public static boolean isConnectionPossible(Context context) {
    try {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(MmsRadio.TYPE_MOBILE_MMS);
        if (networkInfo == null) {
            Log.w(TAG, "MMS network info was null, unsupported by this device");
            return false;
        }
        getApn(context);
        return true;
    } catch (ApnUnavailableException e) {
        Log.w(TAG, e);
        return false;
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 27 with ConnectivityManager

use of android.net.ConnectivityManager in project remusic by aa112901.

the class NetworkUtils method isConnectInternet.

public static boolean isConnectInternet(final Context pContext) {
    final ConnectivityManager conManager = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = conManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        return networkInfo.isAvailable();
    }
    return false;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 28 with ConnectivityManager

use of android.net.ConnectivityManager 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)
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 29 with ConnectivityManager

use of android.net.ConnectivityManager 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;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 30 with ConnectivityManager

use of android.net.ConnectivityManager 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;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)361 NetworkInfo (android.net.NetworkInfo)258 Context (android.content.Context)15 TelephonyManager (android.telephony.TelephonyManager)13 RemoteException (android.os.RemoteException)11 Test (org.junit.Test)11 Intent (android.content.Intent)10 WifiManager (android.net.wifi.WifiManager)9 Method (java.lang.reflect.Method)9 Network (android.net.Network)8 IOException (java.io.IOException)8 PackageManager (android.content.pm.PackageManager)7 SharedPreferences (android.content.SharedPreferences)6 NetworkCapabilities (android.net.NetworkCapabilities)6 UserManager (android.os.UserManager)6 Activity (android.app.Activity)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 IPackageManager (android.content.pm.IPackageManager)5 PackageInfo (android.content.pm.PackageInfo)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5