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:fr.mixit.android.utils.NetworkUtils.java
public static ConnectivityState getConnectivity(Context ctx) { ConnectivityState currentNetworkType; final ConnectivityManager conMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) { NetworkInfo networkInfo = conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null && networkInfo.getState().equals(NetworkInfo.State.CONNECTED)) { currentNetworkType = ConnectivityState.WIFI; } else {/*www .j a v a 2 s . co m*/ networkInfo = conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null && networkInfo.getState().equals(NetworkInfo.State.CONNECTED)) { currentNetworkType = ConnectivityState.CARRIER; } else { // how can we be there ? no wifi and no mobile data but connected ? currentNetworkType = ConnectivityState.UNKNOWN; } } } else { currentNetworkType = ConnectivityState.NONE; } return currentNetworkType; }
From source file:com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidConnectivity.java
private void determineAvailability() { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); inAirplaneMode = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;/*from w w w . j av a 2 s . com*/ log.info("Airplane mode: " + inAirplaneMode); final NetworkInfo networkInfo = cm != null ? cm.getActiveNetworkInfo() : null; int networkType = 0; // default state hasWifi = false; // when we have connectivity manager, we assume we have some sort of // connectivity hasMobile = cm != null; // can we obtain network info? if (networkInfo != null) { if (networkInfo.isConnectedOrConnecting()) { networkType = networkInfo.getType(); hasWifi = networkType == ConnectivityManager.TYPE_WIFI || networkType == ConnectivityManager.TYPE_WIMAX; hasMobile = networkType == ConnectivityManager.TYPE_MOBILE || networkType == ConnectivityManager.TYPE_MOBILE_DUN || networkType == ConnectivityManager.TYPE_MOBILE_HIPRI || networkType == ConnectivityManager.TYPE_MOBILE_MMS || networkType == ConnectivityManager.TYPE_MOBILE_SUPL; } else { // if neither connected or connecting then hasMobile defaults // need to be changed to false hasMobile = false; } } log.info(String.format("Device Connectivity (%s)", hasWifi ? "On Wifi" : (hasMobile ? "On Mobile" : "No network connectivity"))); }
From source file:com.commonsware.android.webserver.secure.WebServerService.java
@Override public void onCreate() { super.onCreate(); ConnectivityManager mgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo ni = mgr.getActiveNetworkInfo(); if (ni == null || ni.getType() == ConnectivityManager.TYPE_MOBILE) { EventBus.getDefault().post(new ServerStartRejectedEvent()); stopSelf();//from w ww . j av a2 s . c om } else { rootPath = "/" + new BigInteger(20, rng).toString(24).toUpperCase(); server = new AsyncHttpServer(); server.get("/.*", new AssetRequestCallback()); server.listen(4999); raiseReadyEvent(); foregroundify(); timeoutFuture = timer.schedule(onTimeout, MAX_IDLE_TIME_SECONDS, TimeUnit.SECONDS); } }
From source file:com.example.qrpoll.Refresh.java
/** * sprawdza, czy w urzadzeniu wlaczona jest obsluga danych pakietowych * @return/* w w w . j ava 2 s. c o m*/ */ public boolean checkNetwork() { ConnectivityManager cm = (ConnectivityManager) activity.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); return ni.isConnected(); }
From source file:com.mytwitter.Network.NetworkHelper.java
public static boolean connectedToWiFiOrMobileNetwork(Context context) { final ConnectivityManager cm = getConnectivityManager(context); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (!isConnected) return false; return (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) || (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE); }
From source file:com.oneguy.recognize.Util.java
public static boolean isNetworkEnable(Context context) { ConnectivityManager con = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE); boolean wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting(); boolean internet = con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting(); return wifi | internet; }
From source file:com.frostwire.android.gui.NetworkManager.java
public boolean isDataMobileUp() { ConnectivityManager connectivityManager = getConnectivityManager(); return isNetworkTypeUp(connectivityManager, ConnectivityManager.TYPE_MOBILE); }
From source file:com.secupwn.aimsicd.utils.Helpers.java
/** * Checks if Network connectivity is available to download OpenCellID data * Requires: android:name="android.permission.ACCESS_NETWORK_STATE" *///from w w w . j av a 2 s . co m public static Boolean isNetAvailable(Context context) { try { ConnectivityManager cM = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = cM.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobileInfo = cM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifiInfo != null && mobileInfo != null) { return wifiInfo.isConnected() || mobileInfo.isConnected(); } } catch (Exception e) { log.error(e.getMessage(), e); } return false; }
From source file:com.orangelabs.rcs.platform.network.AndroidNetworkFactory.java
/** * Returns the local IP address of a given network interface * /*from w w w .ja v a2s . c o m*/ * @param dnsEntry remote address to find an according local socket address * @param type the type of the network interface, should be either * {@link android.net.ConnectivityManager#TYPE_WIFI} or {@link android.net.ConnectivityManager#TYPE_MOBILE} * @return Address */ // Changed by Deutsche Telekom public String getLocalIpAddress(DnsResolvedFields dnsEntry, int type) { String ipAddress = null; try { // What kind of remote address (P-CSCF) are we trying to reach? boolean isIpv4 = InetAddressUtils.isIPv4Address(dnsEntry.ipAddress); // check all available interfaces for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); (en != null) && en.hasMoreElements();) { NetworkInterface netIntf = (NetworkInterface) en.nextElement(); for (Enumeration<InetAddress> addr = netIntf.getInetAddresses(); addr.hasMoreElements();) { InetAddress inetAddress = addr.nextElement(); ipAddress = IpAddressUtils.extractHostAddress(inetAddress.getHostAddress()); // if IP address version doesn't match to remote address // version then skip if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && (InetAddressUtils.isIPv4Address(ipAddress) == isIpv4)) { String intfName = netIntf.getDisplayName().toLowerCase(); // some devices do list several interfaces though only // one is active if (((type == ConnectivityManager.TYPE_WIFI) && intfName.startsWith("wlan")) || ((type == ConnectivityManager.TYPE_MOBILE) && !intfName.startsWith("wlan"))) { return ipAddress; } } } } } catch (Exception e) { if (logger.isActivated()) { logger.error("getLocalIpAddress failed with ", e); } } return ipAddress; }
From source file:biz.shadowservices.DegreesToolbox.DataFetcher.java
public boolean isRoaming(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (info == null) { return false; } else {//from ww w .j a v a2s . c o m return info.isRoaming(); } }