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:de.stadtrallye.rallyesoft.services.UploadService.java
private void updateNetworkStatus() { NetworkInfo activeNetwork = connection.getActiveNetworkInfo(); conn_available = activeNetwork.isConnected(); switch (activeNetwork.getType()) { case (ConnectivityManager.TYPE_WIFI): conn_metered = false;//from ww w.j a va 2s .c o m conn_slow = false; break; case (ConnectivityManager.TYPE_MOBILE): { conn_metered = true; switch (telephony.getNetworkType()) { case (TelephonyManager.NETWORK_TYPE_LTE | TelephonyManager.NETWORK_TYPE_HSPAP | TelephonyManager.NETWORK_TYPE_HSPA)://TODO more + check conn_slow = false; break; case (TelephonyManager.NETWORK_TYPE_EDGE | TelephonyManager.NETWORK_TYPE_GPRS): conn_slow = true; break; default: conn_slow = false; break; } break; } default: conn_metered = false; conn_slow = false; break; } Log.d(THIS, "Network: available: " + conn_available + ", metered: " + conn_metered + ", slow: " + conn_slow); }
From source file:com.mobeelizer.mobile.android.MobeelizerRealConnectionManagerTest.java
@Before public void init() throws Exception { PowerMockito.mockStatic(Log.class); PowerMockito.when(Log.class, "i", anyString(), anyString()).thenReturn(0); PowerMockito.when(Log.class, "e", anyString(), anyString()).thenReturn(0); PowerMockito.when(Log.class, "e", anyString(), anyString(), any(Throwable.class)).thenReturn(0); PowerMockito.mockStatic(Proxy.class); PowerMockito.when(Proxy.class, "getHost", any(Context.class)).thenReturn(null); PowerMockito.when(Proxy.class, "getPort", any(Context.class)).thenReturn(-1); httpClient = PowerMockito.mock(DefaultHttpClient.class); whenNew(DefaultHttpClient.class) .withArguments(any(ClientConnectionManager.class), any(BasicHttpParams.class)) .thenReturn(httpClient);//from ww w . j ava 2 s .c om httpConnectionManager = PowerMockito.mock(ClientConnectionManager.class); when(httpClient.getConnectionManager()).thenReturn(httpConnectionManager); httpGet = PowerMockito.mock(HttpGet.class); whenNew(HttpGet.class).withArguments(anyString()).thenReturn(httpGet); httpPost = PowerMockito.mock(HttpPost.class); whenNew(HttpPost.class).withArguments(anyString()).thenReturn(httpPost); httpResponse = PowerMockito.mock(HttpResponse.class); when(httpClient.execute(httpGet)).thenReturn(httpResponse); when(httpClient.execute(httpPost)).thenReturn(httpResponse); httpEntity = PowerMockito.mock(HttpEntity.class); when(httpResponse.getEntity()).thenReturn(httpEntity); httpStatusLine = PowerMockito.mock(StatusLine.class); when(httpResponse.getStatusLine()).thenReturn(httpStatusLine); when(httpStatusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); application = mock(MobeelizerApplication.class); when(application.getVendor()).thenReturn("vendor"); when(application.getApplication()).thenReturn("application"); when(application.getInstance()).thenReturn("instance"); when(application.getDevice()).thenReturn("device"); when(application.getDeviceIdentifier()).thenReturn("deviceIdentifier"); when(application.getUser()).thenReturn("user"); when(application.getPassword()).thenReturn("password"); when(application.getUrl()).thenReturn("http://url/app"); Context context = PowerMockito.mock(Context.class); when(application.getContext()).thenReturn(context); ConnectivityManager connectivityService = PowerMockito.mock(ConnectivityManager.class); when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityService); networkWifiInfo = PowerMockito.mock(NetworkInfo.class); when(connectivityService.getNetworkInfo(ConnectivityManager.TYPE_WIFI)).thenReturn(networkWifiInfo); when(networkWifiInfo.isConnected()).thenReturn(true); NetworkInfo networkMobileInfo = PowerMockito.mock(NetworkInfo.class); when(connectivityService.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)).thenReturn(networkMobileInfo); database = mock(MobeelizerInternalDatabase.class); when(application.getInternalDatabase()).thenReturn(database); connectionManager = new MobeelizerRealConnectionManager(application); }
From source file:com.nextgis.metroaccess.MetaDownloader.java
static boolean IsNetworkAvailible(Context c) { ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null) { int netType = info.getType(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && !tm.isNetworkRoaming()) { return info.isConnected(); }//from w w w .j a v a2 s . c o m } return false; }
From source file:com.github.ignition.support.http.IgnitedHttpClient.java
public void updateProxySettings() { if (appContext == null) { return;//from w ww.j a v a 2 s .com } 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:com.fairphone.updater.UpdaterService.java
private boolean hasInternetConnection() { ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); boolean is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting(); boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting(); return isWifi || is3g; }
From source file:ti.modules.titanium.network.NetworkModule.java
protected int networkTypeToTitanium(boolean online, int androidType) { int type = NetworkModule.NETWORK_UNKNOWN; if (online) { switch (androidType) { case ConnectivityManager.TYPE_WIFI: type = NetworkModule.NETWORK_WIFI; break; case ConnectivityManager.TYPE_MOBILE: type = NetworkModule.NETWORK_MOBILE; break; default:/*from www . j a v a2s. com*/ type = NetworkModule.NETWORK_UNKNOWN; } } else { type = NetworkModule.NETWORK_NONE; } return type; }
From source file:org.kei.android.phone.cellhistory.towers.MobileNetworkInfo.java
public static int getConnectivityStatus(final Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (null != activeNetwork) { if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) return TYPE_WIFI; if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) return TYPE_MOBILE; }//from w w w .j av a 2 s. c o m return TYPE_NOT_CONNECTED; }
From source file:itesm.mx.golpedecalor.SelectGroupActivity.java
public void onClickSincronizar(View v) { ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mMobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mWifi.isConnected() || mMobile.isConnected()) { new RequestTask().execute("http://golpedecalor.comoj.com/dbHandler.php"); Toast.makeText(getApplicationContext(), "Sincronizacion Exitosa", Toast.LENGTH_SHORT).show(); } else {/* ww w .j av a2 s . c o m*/ Toast.makeText(getApplicationContext(), "No hay conexin a internet", Toast.LENGTH_SHORT).show(); } }
From source file:com.nextgis.firereporter.HttpGetter.java
static boolean IsNetworkAvailible(Context c) { ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null /*|| !cm.getBackgroundDataSetting()*/) return false; int netType = info.getType(); //int netSubtype = info.getSubtype(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && /*netSubtype == TelephonyManager.NETWORK_TYPE_UMTS &&*/ !tm.isNetworkRoaming()) { return info.isConnected(); } else {// w ww. ja v a 2s .c o m return false; } }
From source file:com.iflytek.android.framework.volley.toolbox.HurlStack.java
/** * @param context/* w w w. java 2s. com*/ * @return ???<br\> * -1: 1:WIFI <br\> * 2:cmnet 3:cmwap <br\> * 4:ctnet 5:ctwap <br\> * ? 6:uninet 7:uniwap */ public static int getAPNType(Context context) { // ?wificmnet?cmwap??noneNet // ?wifi > cmnet >cmwap > noneNet ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo == null) { return -1; } int nType = networkInfo.getType(); if (nType == ConnectivityManager.TYPE_WIFI) { // wifi return 1; } else if (nType == ConnectivityManager.TYPE_MOBILE) { String type = networkInfo.getExtraInfo(); Log.d("netType", "netType : " + type); if (type.equalsIgnoreCase("cmnet")) { // cmnet return 2; } else if (type.equalsIgnoreCase("cmwap")) { // cmwap return 3; } else if (type.equalsIgnoreCase("ctnet")) { // ctnet return 4; } else if (type.equalsIgnoreCase("ctwap")) { // ctwap return 5; } else if (type.equalsIgnoreCase("uninet")) { // uninet return 6; } else if (type.equalsIgnoreCase("uniwap")) { // uniwap return 7; } else { return 2; } } return -1; }