List of usage examples for android.net NetworkInfo getType
@Deprecated public int getType()
From source file:com.nextgis.maplib.util.NetworkUtil.java
public boolean isNetworkAvailable() { if (mConnectionManager == null) { return false; }/*from ww w . ja v a 2s .c o m*/ NetworkInfo info = mConnectionManager.getActiveNetworkInfo(); if (info == null) //|| !cm.getBackgroundDataSetting() { return false; } int netType = info.getType(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE) { // netSubtype == TelephonyManager.NETWORK_TYPE_UMTS if (mTelephonyManager != null && !mTelephonyManager.isNetworkRoaming()) { return info.isConnected(); } } return false; }
From source file:com.quuzz.tbg.recyclerview.MainActivity.java
/** * Check whether the device is connected, and if so, whether the connection * is wifi or mobile (it could be something else). *//*from w w w. j ava2s. c om*/ private void checkNetworkConnection() { 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, "wifi connected"); } else if (mobileConnected) { Log.i(TAG, "mobile connected"); } } else { Log.i(TAG, "no internet connections"); } }
From source file:com.bangz.smartmute.WifiEditActivity.java
@Override public void onSuccessUpdateDatabase(Uri uri) { if (bActivited == false) return;/* ww w .j a v a 2s . c o m*/ ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo ninfo = cm.getActiveNetworkInfo(); if (ninfo != null && ninfo.isConnected() && ninfo.getType() == ConnectivityManager.TYPE_WIFI) { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); if (wifiManager != null) { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String currssid = wifiInfo.getSSID(); if (currssid.equals(strSSID)) { WifiMuteService.wifiConnected(this, strSSID); } } } }
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 w w . j a va2s . com } 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.android.basicnetworking.MainActivity.java
/** * Check whether the device is connected, and if so, whether the connection * is wifi or mobile (it could be something else). *//* w w w . j a v a2 s. co m*/ private void checkNetworkConnection() { 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)); } }
From source file:net.primeranks.fs_viewer.fs_replay.ConnectionChangedBroadcastReceiver.java
public void onReceive(Context context, Intent intent) { String info = intent.getStringExtra(ConnectivityManager.EXTRA_EXTRA_INFO); NetworkInfo nwInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); Log.d(Config.LOG_AS, info + ": " + nwInfo.getReason()); HttpParams httpParams = EntryPointActivity.getHttpClient().getParams(); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(context); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); }//from ww w .j a va 2 s. c o m 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:com.onesignal.OSUtils.java
Integer getNetType() { ConnectivityManager cm = (ConnectivityManager) OneSignal.appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null) { int networkType = netInfo.getType(); if (networkType == ConnectivityManager.TYPE_WIFI || networkType == ConnectivityManager.TYPE_ETHERNET) return 0; return 1; }//from ww w. j av a 2s . c om return null; }
From source file:com.raywenderlich.reposearch.MainActivity.java
private boolean isWifiConnected() { ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return networkInfo != null && (ConnectivityManager.TYPE_WIFI == networkInfo.getType()) && networkInfo.isConnected(); }
From source file:com.OpenSource.engine.connectivity.ConnectivityInfoProvider.java
public int getActiveNetworkType() { NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { return -1; }//from w w w . j a v a 2 s .co m return networkInfo.getType(); }
From source file:com.tbay.android.tcpclient.MainActivity.java
/** * Check whether the device is connected, and if so, whether the connection * is wifi or mobile (it could be something else). *///w w w. ja v a 2s . co m 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) }