List of usage examples for android.net NetworkInfo isConnectedOrConnecting
@Deprecated public boolean isConnectedOrConnecting()
From source file:net.okjsp.imageloader.ImageFetcher.java
/** * Simple network connection check.//from w w w . j a v a2s.c o m * * @param context */ private void checkConnection(Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) { //Toast.makeText(context, "No network connection found.", Toast.LENGTH_LONG).show(); Log.e(TAG, "checkConnection - no connection found"); } }
From source file:com.owncloud.activity.Downloader.java
public boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { // Try This int i = netInfo.getType(); System.out.println("Net Type =" + i); return true; }//from w w w . j a v a2 s . c o m return false; }
From source file:com.manning.androidhacks.hack040.util.ImageFetcher.java
/** * Simple network connection check.//from w w w .ja v a 2s .com * * @param context */ private void checkConnection(Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) { Toast.makeText(context, "No network connection found.", Toast.LENGTH_LONG).show(); Log.e(TAG, "checkConnection - no connection found"); } }
From source file:org.ocs.android.agent.service.OCSAgentService.java
private boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { if (mOcssetting.getAutoModeNetwork() == AUTOMODE_NOROAMING && !netInfo.isRoaming()) { return true; // no roaming }//from www . ja v a2 s . c om if (mOcssetting.getAutoModeNetwork() == AUTOMODE_ANY) { return true; // any network (including roaming) } if (mOcssetting.getAutoModeNetwork() == AUTOMODE_WIFI && netInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; // wifi only } } return false; }
From source file:de.tu_berlin.snet.probe.FacebookProbe.java
private boolean isAvailable() { ConnectivityManager connMgr = (ConnectivityManager) getContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connMgr.getActiveNetworkInfo(); if (!wifiOnly && netInfo != null && netInfo.isConnectedOrConnecting()) { return true; } else if (wifiOnly) { NetworkInfo.State wifiInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); if (NetworkInfo.State.CONNECTED.equals(wifiInfo) || NetworkInfo.State.CONNECTING.equals(wifiInfo)) return true; }//from w ww . ja v a 2s. com return false; }
From source file:me.onemobile.client.image.ImageFetcher.java
/** * Simple network connection check.// w ww . ja v a2s . c o m * * @param context */ private void checkConnection(Context context) { final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) { // Toast.makeText(context, "No network connection found.", Toast.LENGTH_LONG).show(); } }
From source file:com.cellobject.oikos.util.NetworkHelper.java
public boolean isOnline() { final ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); if ((netInfo != null) && netInfo.isConnectedOrConnecting()) { return true; }//from ww w .j av a2s . c o m return false; }
From source file:de.jadehs.jadehsnavigator.fragment.InfoSysFragment.java
/** * Updates the view for this fragment if a internet connection is available * * @param isSwipeRefresh/*from ww w . j a v a 2 s. co m*/ */ public void updateInfoSys(boolean isSwipeRefresh) { Log.wtf(TAG, "Starting updateInfoSys"); this.preferences = new Preferences(getActivity().getApplicationContext()); TextView txtLastUpdate = (TextView) getActivity().findViewById(R.id.txtLastUpdate); ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (isConnected) { try { /* launches an asynchronus task that will fetch all infosys items for the current department */ this.asyncTask = new ParseInfoSysTask(getActivity(), this.preferences.getInfoSysURL(), this.preferences.getFB(), isSwipeRefresh); this.asyncTask.delegate = this; this.asyncTask.execute(); } catch (Exception ex) { Log.wtf(TAG, "INTERNET LOAD", ex); } } else { txtLastUpdate.setText("Um neue Eintrge abzurufen, bitte Internetverbindung herstellen"); swipeLayout.setRefreshing(false); } }
From source file:com.armannds.eldgos.katla.popularmovies.ui.MainActivity.java
private boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); }
From source file:de.jadehs.jadehsnavigator.fragment.NewsFragment.java
public void updateRSSFeeds() { Log.wtf(TAG, "Starting updateRSSFeeds"); ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (isConnected) { try {/*from ww w . ja va 2s . c om*/ /* Load RSS origins from asset file and create a list with RSS origins */ ArrayList<RSSOrigin> origins = new ArrayList<RSSOrigin>(); JSONObject obj = new JSONObject(loadJSONFromAsset()); JSONArray jArray = obj.getJSONArray("origins"); RSSOrigin rssOrigin; for (int i = 0; i < jArray.length(); i++) { JSONObject origin = jArray.getJSONObject(i); rssOrigin = new RSSOrigin(origin.getLong("id"), origin.getString("title"), origin.getString("url")); origins.add(rssOrigin); } /* Start parsing */ ParseRSSTask rssTask = new ParseRSSTask(getActivity(), origins); rssTask.delegate = this; rssTask.execute(); } catch (Exception ex) { Log.wtf(TAG, "Failed to parse", ex); } } else { Log.wtf(TAG, "NO INTERNET CONNECTION"); //@todo: footer //getActivity().findViewById(R.id.errorOverlay).setVisibility(View.VISIBLE); // Displays the error overlay } }