List of usage examples for android.net NetworkInfo isConnected
@Deprecated public boolean isConnected()
From source file:se.bitcraze.crazyfliecontrol.bootloader.FirmwareDownloader.java
/** * Check network connectivity/* www .java 2 s. co m*/ * * @return true if network is available, false otherwise */ private boolean isNetworkAvailable() { ConnectivityManager connMgr = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnected(); }
From source file:com.QuarkLabs.BTCeClient.services.CheckTickersService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sh = PreferenceManager.getDefaultSharedPreferences(this); Set<String> x = sh.getStringSet("PairsToDisplay", new HashSet<String>()); if (x.size() == 0) { return;/*w w w .j a va 2 s . c o m*/ } String[] pairs = x.toArray(new String[x.size()]); ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); String url = BASE_URL; for (String xx : pairs) { url += xx.replace("/", "_").toLowerCase(Locale.US) + "-"; } SimpleRequest reqSim = new SimpleRequest(); if (networkInfo != null && networkInfo.isConnected()) { JSONObject data = null; try { data = reqSim.makeRequest(url); } catch (JSONException e) { e.printStackTrace(); } if (data != null && data.optInt("success", 1) != 0) { ArrayList<Ticker> tickers = new ArrayList<>(); for (@SuppressWarnings("unchecked") Iterator<String> iterator = data.keys(); iterator.hasNext();) { String key = iterator.next(); JSONObject pairData = data.optJSONObject(key); Ticker ticker = new Ticker(key); ticker.setUpdated(pairData.optLong("updated")); ticker.setAvg(pairData.optDouble("avg")); ticker.setBuy(pairData.optDouble("buy")); ticker.setSell(pairData.optDouble("sell")); ticker.setHigh(pairData.optDouble("high")); ticker.setLast(pairData.optDouble("last")); ticker.setLow(pairData.optDouble("low")); ticker.setVol(pairData.optDouble("vol")); ticker.setVolCur(pairData.optDouble("vol_cur")); tickers.add(ticker); } String message = checkNotifiers(tickers, TickersStorage.loadLatestData()); if (message.length() != 0) { NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); NotificationCompat.Builder nb = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)) .setSmallIcon(R.drawable.ic_stat_bitcoin_sign) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentText(message.substring(0, message.length() - 2)); notificationManager.notify(ConstantHolder.ALARM_NOTIF_ID, nb.build()); } Map<String, Ticker> newData = new HashMap<>(); for (Ticker ticker : tickers) { newData.put(ticker.getPair(), ticker); } TickersStorage.saveData(newData); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("UpdateTickers")); } } else { new Handler().post(new Runnable() { @Override public void run() { //Toast.makeText(CheckTickersService.this, "Unable to fetch data", Toast.LENGTH_SHORT).show(); } }); } }
From source file:com.alex.smartwomanmiddleeastfem.WebViewDemoActivity.java
/** * Checks networking status./*from w w w . j a v a 2s. c o m*/ */ private boolean checkConnectivity() { boolean enabled = true; ConnectivityManager connectivityManager = (ConnectivityManager) this .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); if ((info == null || !info.isConnected() || !info.isAvailable())) { } return enabled; }
From source file:com.stepinmobile.fantasticbutton.api.ButtonHandle.java
/** * Method check internet connection and retrieve boolean result. * @return true if network available/*from w ww . ja v a 2s . com*/ */ private boolean isNetworkAvailable() { boolean isAvailable = false; ConnectivityManager manager = (ConnectivityManager) aq.getContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); // if no network is available networkInfo will be null // otherwise check if we are connected if (networkInfo != null && networkInfo.isConnected()) { isAvailable = true; } return isAvailable; }
From source file:foam.littlej.android.app.net.MainHttpClient.java
/** * Is there internet connection//from w w w. ja v a2 s . c o m */ public boolean isConnected() { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo; networkInfo = connectivity.getActiveNetworkInfo(); // NetworkInfo info if (networkInfo != null && networkInfo.isConnected() && networkInfo.isAvailable()) { return true; } return false; }
From source file:com.google.samples.quickstart.signin.MainActivity.java
private void onSignInClicked() { // User clicked the sign-in button, so begin the sign-in process and automatically // attempt to resolve any errors that occur. ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { mShouldResolve = true;/*from ww w.j av a2 s . com*/ mGoogleApiClient.connect(); // Show a message to the user that we are signing in. mStatus.setText(R.string.signing_in); } else { Context context = getApplicationContext(); CharSequence text = "Please check your Network Connection"; int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.show(); return; } }
From source file:com.magnux.iobahn.simpleevents.SimpleEventsActivity.java
public boolean isNetworkAvailable() { ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if (ni != null && ni.isConnected()) { // System.out.println("ni.isConnected() = "+ni.isConnected()); return ni.isConnected(); } else {/*from w w w . j a v a 2s. c om*/ // System.out.println("ni.isConnected() = "+ni.isConnected()); return false; } }
From source file:biz.shadowservices.DegreesToolbox.DataFetcher.java
public boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null) { return false; } else {/*from w ww. j a v a 2 s.co m*/ return info.isConnected(); } }
From source file:com.albedinsky.android.support.universi.UniversiContextDelegate.java
/** * Checks whether the current active network is at this time connected or not. * * @return {@code True} if active network is connected, {@code false} otherwise. * @see ConnectivityManager#getActiveNetworkInfo() * @see NetworkInfo#isConnected()/*from ww w. j a v a 2 s. c om*/ * @see #isNetworkConnected(int) */ @CheckResult public boolean isActiveNetworkConnected() { this.ensureConnectivityManager(); final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); return info != null && info.isConnected(); }