List of usage examples for android.net NetworkInfo isConnected
@Deprecated public boolean isConnected()
From source file:biz.shadowservices.DegreesToolbox.DataFetcher.java
public boolean isWifi(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info == null) { return false; } else {//from ww w . j av a 2 s . c o m return info.isConnected(); } }
From source file:com.danielme.muspyforandroid.activities.base.AbstractActivity.java
/** * Checks internet connection. Shows a dialog if it ain't available. *//*from w w w . j a va 2 s.com*/ public boolean checkConnection() { ConnectivityManager connectivityManager = (ConnectivityManager) this .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); if ((noConnectionDialog == null || !noConnectionDialog.isShowing()) && (info == null || !info.isConnected() || !info.isAvailable())) { Builder builder = new Builder(this); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setMessage(getString(R.string.noconnection)); builder.setCancelable(false); builder.setNeutralButton(R.string.ok, null); builder.setTitle(getString(R.string.error)); noConnectionDialog = builder.create(); noConnectionDialog.show(); dialogStyle(noConnectionDialog); return false; } else { return true; } }
From source file:com.meiste.greg.ptw.GAE.java
private boolean isOnline() { final ConnectivityManager cm = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); return (netInfo != null) && (netInfo.isConnected()); }
From source file:com.fine47.http.ActivityHttpClient.java
/** * Checks whether the system is online (connected to a network) or not. * * @return TRUE if the system is online, FALSE otherwise *///from w ww. ja va 2 s .c o m public boolean isOnline() { try { ConnectivityManager cm = (ConnectivityManager) getContext().getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (null != netInfo) { // Check for availability and if it's really connected. isConnected = netInfo.isAvailable() && netInfo.isConnectedOrConnecting(); // Get available networks' info. NetworkInfo[] netsInfo = cm.getAllNetworkInfo(); // What kind of networks are available. for (NetworkInfo ni : netsInfo) { if (ni.isConnected()) { String niType = ni.getTypeName(); if ("WIFI".equalsIgnoreCase(niType)) { isWifiConnected = true; } else if ("MOBILE".equalsIgnoreCase(niType)) { isMobileConnected = true; } } } } else { isConnected = false; } return isConnected; } catch (Throwable error) { if (isDebugging()) { Log.e(LOG_TAG, "Error while detecting network status.", error); } } return isConnected; }
From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java
public void poll() { ConnectivityManager cm = (ConnectivityManager) ctx.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni == null || !ni.isConnected()) { Log.d(TAG, "poll() when not connected"); schedule(RESCHEDULE_NOT_CONNECTED); return;//from ww w . j ava2 s . c o m } try { if (new ForegroundCheckTask().execute(ctx).get()) { Log.d(TAG, "poll() when foreground"); schedule(RESCHEDULE_FOREGROUND); } else { Log.d(TAG, "poll() when background"); pollBackground(); } } catch (Exception e) { Log.e(TAG, "poll() failed", e); } }
From source file:com.esri.cordova.geolocation.AdvancedGeolocation.java
/** * Check for <code>Network</code> connection. * Checks for generic Exceptions and writes them to logcat as <code>CheckConnectivity Exception</code>. * Make sure AndroidManifest.xml has appropriate permissions. * @param con Application context/*from ww w . j a v a2s. c om*/ * @return Boolean */ private Boolean isInternetConnected(Context con) { Boolean connected = false; try { final ConnectivityManager connectivityManager = (ConnectivityManager) con .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo.isConnected()) { connected = true; } } catch (Exception e) { Log.e(TAG, "CheckConnectivity Exception: " + e.getMessage()); } return connected; }
From source file:com.polyvi.xface.extension.telephony.XTelephonyExt.java
/** * sim???//from w ww. ja v a 2 s.c om * * @param context * @return */ public boolean isSimCardAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); return (info != null && info.isConnected() && checkSimCardState(tm)); }
From source file:edu.rit.csh.androidwebnews.HttpsConnector.java
/** * Checks to see if there is network connection * * @return boolean - true if there is internet, false otherwise *//*from w w w.j a v a 2 s . c o m*/ boolean checkInternet() { ConnectivityManager connect = (ConnectivityManager) activity.getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = connect.getActiveNetworkInfo(); return ni != null && ni.isConnected(); }
From source file:com.chalmers.schmaps.GoogleMapSearchLocation.java
/** * Check if the device is connected to internet. * Need three if-statements because getActiveNetworkInfo() may return null * and end up with a force close. So thats the last thing to check. * @return true if there is an internet connection */// ww w. j a va2 s . co m public boolean gotInternetConnection() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null && wifiNetwork.isConnected()) { return true; } NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetwork != null && mobileNetwork.isConnected()) { return true; } NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null && activeNetwork.isConnected()) { return true; } return false; }
From source file:net.kourlas.voipms_sms.Api.java
/** * Tests whether or not there is a network connection available. * * @return true if there is an available network connection, false otherwise. *//*from w w w . j a va 2s. com*/ private boolean isNetworkConnectionAvailable() { ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnected(); }