List of usage examples for android.net NetworkInfo isConnected
@Deprecated public boolean isConnected()
From source file:com.nextgis.maplib.util.NetworkUtil.java
public boolean isNetworkAvailable() { if (mConnectionManager == null) { return false; }//w w w . j a v a2 s .co 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:jp.takuo.android.mmsreq.Request.java
protected void getConnectivity() throws NoConnectivityException, ConnectTimeoutException, InterruptedException { mConnMgr = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); if (!mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS).isAvailable()) { throw new NoConnectivityException(mContext.getString(R.string.not_available)); }/*from w w w. jav a 2 s. c o m*/ int count = 0; int result = beginMmsConnectivity(mConnMgr); if (result != APN_ALREADY_ACTIVE) { NetworkInfo info = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS); while (!info.isConnected()) { Thread.sleep(1500); info = mConnMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS); Log.d(LOG_TAG, "Waiting for CONNECTED: state=" + info.getState()); if (count++ > 5) throw new ConnectTimeoutException(mContext.getString(R.string.failed_to_connect)); } } Thread.sleep(1500); // wait for adding dns }
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:amhamogus.com.daysoff.MainActivity.java
/** * Checks whether the device currently has a network connection. * * @return true if the device has a network connection, false otherwise. *//*from www . j av a2s . c om*/ private boolean isDeviceOnline() { ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return (networkInfo != null && networkInfo.isConnected()); }
From source file:org.mrquiz.android.tinyurl.SendTinyUrlActivity.java
private boolean networkConnected() { boolean result = false; ConnectivityManager CM = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (CM == null) { result = false;// w w w . j a va 2 s .co m } else { NetworkInfo info = CM.getActiveNetworkInfo(); if (info != null && info.isConnected()) { if (!info.isAvailable()) { result = false; } else { result = true; } } } return result; }
From source file:com.android.browser.search.OpenSearchSearchEngine.java
private boolean isNetworkConnected(Context context) { NetworkInfo networkInfo = getActiveNetworkInfo(context); return networkInfo != null && networkInfo.isConnected(); }
From source file:com.mobshep.insufficienttls.InsufficientTLS.java
public boolean isNetworkAvailable() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getActiveNetworkInfo(); // if no network is available networkInfo will be null // otherwise check if we are connected if (networkInfo != null && networkInfo.isConnected()) { return true; }// w ww . j av a 2s . c o m return false; }
From source file:com.chess.genesis.net.GenesisNotifier.java
private boolean internetIsActive() { final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); return (netInfo != null && netInfo.isConnected()); }
From source file:de.teambluebaer.patientix.activities.LoginActivity.java
/** * On press of the "Login" button, the users can access to the APP * with their PIN and after the StartActivity will be loaded. * * @param v default parameter to change something of the view *//*from w w w .j a va 2 s . c om*/ public void onClickLoginButton(View v) { ConnectivityManager connManager = (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWifi.isConnected()) { if (passwordHash(editTextPassword.getText().toString()).equals(Constants.PIN)) { new GetTabletID().execute(); } else { editTextPassword.setText(""); Toast.makeText(this, "Falscher PIN!!!", Toast.LENGTH_LONG).show(); } } else { editTextPassword.setText(""); Toast.makeText(this, "WiFi ist abgeschaltet, bitte schalten sie das WiFi wieder ein.", Toast.LENGTH_LONG).show(); } }
From source file:de.electricdynamite.pasty.PastyLoader.java
@Override protected void onStartLoading() { if (mConnMgr == null) { mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); }/*from w w w . j a v a 2s. c o m*/ NetworkInfo networkInfo = mConnMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { this.isOnline = true; } else { this.isOnline = false; } networkInfo = null; if (mCachePastyResponse != null && permitCache) { // Instantly return a cached version if (LOCAL_LOG) Log.v(TAG, "onStartLoading(): Delivering result from memory"); super.deliverResult(mCachePastyResponse); } else if (firstLoad && permitCache) { JSONArray jsonCache = getCachedClipboard(); if (jsonCache != null) { // Got clipboard from device cache if (LOCAL_LOG) Log.v(TAG, "onStartLoading(): Delivering result from cache"); if (!isOnline) { deliverResult(new PastyResponse(jsonCache, PastyResponse.SOURCE_CACHE, true)); } else { deliverResult(new PastyResponse(jsonCache, PastyResponse.SOURCE_CACHE)); } firstLoad = false; } else { if (!isOnline) { PastyException e = new PastyException(PastyException.ERROR_NO_CACHE_EXCEPTION); deliverResult(new PastyResponse(e)); } } } if (isOnline) { forceLoad(); } }