List of usage examples for android.net ConnectivityManager TYPE_MOBILE
int TYPE_MOBILE
To view the source code for android.net ConnectivityManager TYPE_MOBILE.
Click Source Link
From source file:com.andrew.apollo.utils.ApolloUtils.java
/** * Used to determine if there is an active data connection and what type of * connection it is if there is one/*from w w w. ja v a 2s. c o m*/ * * @param context The {@link Context} to use * @return True if there is an active data connection, false otherwise. * Also, if the user has checked to only download via Wi-Fi in the * settings, the mobile data and other network connections aren't * returned at all */ public static final boolean isOnline(final Context context) { /* * This sort of handles a sudden configuration change, but I think it * should be dealt with in a more professional way. */ if (context == null) { return false; } boolean state = false; final boolean onlyOnWifi = PreferenceUtils.getInstace(context).onlyOnWifi(); /* Monitor network connections */ final ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); /* Wi-Fi connection */ final NetworkInfo wifiNetwork = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null) { state = wifiNetwork.isConnectedOrConnecting(); } /* Mobile data connection */ final NetworkInfo mbobileNetwork = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mbobileNetwork != null) { if (!onlyOnWifi) { state = mbobileNetwork.isConnectedOrConnecting(); } } /* Other networks */ final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); if (activeNetwork != null) { if (!onlyOnWifi) { state = activeNetwork.isConnectedOrConnecting(); } } return state; }
From source file:dev.ukanth.ufirewall.InterfaceTracker.java
public static boolean checkForNewCfg(Context context) { InterfaceDetails newCfg = getInterfaceDetails(context); if (currentCfg != null && currentCfg.equals(newCfg)) { return false; }//from ww w . j a v a 2 s .c o m currentCfg = newCfg; if (!newCfg.netEnabled) { Log.i(TAG, "Now assuming NO connection (all interfaces down)"); } else { if (newCfg.netType == ConnectivityManager.TYPE_WIFI) { Log.i(TAG, "Now assuming wifi connection"); } else if (newCfg.netType == ConnectivityManager.TYPE_MOBILE) { Log.i(TAG, "Now assuming 3G connection (" + (newCfg.isRoaming ? "roaming, " : "") + (newCfg.isTethered ? "tethered" : "non-tethered") + ")"); } if (!newCfg.lanMaskV4.equals("")) { Log.i(TAG, "IPv4 LAN netmask on " + newCfg.wifiName + ": " + newCfg.lanMaskV4); } if (!newCfg.lanMaskV6.equals("")) { Log.i(TAG, "IPv6 LAN netmask on " + newCfg.wifiName + ": " + newCfg.lanMaskV6); } } return true; }
From source file:org.egov.android.view.activity.RegisterActivity.java
/** * internet connection test function/*from w ww. j a v a 2 s . c o m*/ */ public boolean isInternetAvailable() { ConnectivityManager connectivity = (ConnectivityManager) getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI); boolean available = false; if (netInfo.isConnected()) { available = true; } else { netInfo = connectivity.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); available = netInfo.isConnected(); } return available; }
From source file:com.DGSD.DGUtils.Http.BetterHttp.java
public static void updateProxySettings() { if (appContext == null) { return;//from w w w. ja va2 s . c o m } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(appContext); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:org.ametro.app.ApplicationEx.java
public boolean isAutoUpdateNetworkAvailable() { boolean isWifiConnected = mConnectionManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected(); boolean isMobileConnected = mConnectionManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) .isConnected();//from www.j av a 2 s . c o m boolean isConnected = false; if (GlobalSettings.isUpdateOnlyByWifi(this)) { isConnected = isWifiConnected; } else if (!GlobalSettings.isUpdateByAnyNetwork(this)) { isConnected = isWifiConnected || isMobileConnected; } else { isConnected = isNetworkAvailable(); } return isConnected; }
From source file:jp.takuo.android.mmsreq.Request.java
protected void disconnect() { Log.d(LOG_TAG, "stopUsingNetworkFeature: MOBILE, enableMMS"); mConnMgr.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, "enableMMS"); }
From source file:com.appassit.common.Utils.java
/** * Returns whether the network is roaming *///from w w w .j a va 2 s .c o m public static boolean isNetworkRoaming(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { // Log.w(Constants.TAG, "couldn't get connectivity manager"); } else { NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE) { } else { } } return false; }
From source file:org.kei.android.phone.cellhistory.towers.MobileNetworkInfo.java
public static String getTheoreticalSpeed(final NetworkInfo ni) { if (ni.getType() == ConnectivityManager.TYPE_MOBILE) { switch (ni.getSubtype()) { case TelephonyManager.NETWORK_TYPE_1xRTT: return "~50-100 kbps"; case TelephonyManager.NETWORK_TYPE_CDMA: return "~14-64 kbps"; case TelephonyManager.NETWORK_TYPE_EDGE: return "~50-100 kbps"; case TelephonyManager.NETWORK_TYPE_EVDO_0: return "~400-1000 kbps"; case TelephonyManager.NETWORK_TYPE_EVDO_A: return "~600-1400 kbps"; case TelephonyManager.NETWORK_TYPE_GPRS: return "~100 kbps"; case TelephonyManager.NETWORK_TYPE_HSDPA: return "~2-14 Mbps"; case TelephonyManager.NETWORK_TYPE_HSPA: return "~700-1700 kbps"; case TelephonyManager.NETWORK_TYPE_HSUPA: return "~1-23 Mbps"; case TelephonyManager.NETWORK_TYPE_UMTS: return "~400-7000 kbps"; case TelephonyManager.NETWORK_TYPE_EHRPD: return "~1-2 Mbps"; case TelephonyManager.NETWORK_TYPE_EVDO_B: return "~5 Mbps"; case TelephonyManager.NETWORK_TYPE_HSPAP: return "~10-20 Mbps"; case TelephonyManager.NETWORK_TYPE_IDEN: return "~25 kbps"; case TelephonyManager.NETWORK_TYPE_LTE: return "~10+ Mbps"; }/*from w ww. j av a 2s. co m*/ } return TowerInfo.UNKNOWN; }
From source file:cn.edu.szjm.support.http.IgnitedHttp.java
/** * Updates the underlying HTTP client's proxy settings with what the user has entered in the APN * settings. This will be called automatically if {@link #listenForConnectivityChanges(Context)} * has been called. <b>This requires the {@link Manifest.permission#ACCESS_NETWORK_STATE} * permission</b>.//from w w w . j a v a 2 s . c o m * * @param context * the current context */ public void updateProxySettings(Context context) { if (context == null) { return; } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(context); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(context); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }
From source file:pubsub.io.android.Pubsub.java
/** * Detects if we have internet or not, checks both WiFi and 3G. * //from www . j a va 2s . com * @return */ public boolean hasInternet() { if (DEBUG) Log.i(TAG, "hasInternet()"); ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); if (DEBUG) Log.i(TAG, "Testing WiFi status"); // First test wifi for status! NetworkInfo netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (netInfo != null && netInfo.isConnectedOrConnecting()) { if (DEBUG) Log.i(TAG, "WiFi detected, connecting"); return true; } if (DEBUG) Log.i(TAG, "No WiFi detected, trying mobile"); netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (netInfo != null && netInfo.isConnectedOrConnecting()) { if (DEBUG) Log.i(TAG, "Mobile detected, connecting"); return true; } if (DEBUG) Log.i(TAG, "No Mobile detected, aborting"); return false; }