List of usage examples for android.net NetworkInfo isConnectedOrConnecting
@Deprecated public boolean isConnectedOrConnecting()
From source file:com.example.cal.mysunshine.Utility.java
public static boolean isConnected(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); }
From source file:com.ota.updates.utils.Utils.java
public static boolean isConnected(Context context) { boolean isConnected = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null) { isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); }/*w w w .j ava 2 s. com*/ } return isConnected; }
From source file:com.ruesga.rview.misc.CacheHelper.java
@SuppressLint("Deprecated") public static void downloadAttachmentFile(Context context, Attachment attachment) throws IOException { OkHttpClient client = NetworkingHelper.createNetworkClient().addNetworkInterceptor(chain -> { Response originalResponse = chain.proceed(chain.request()); return CacheHelper.addCacheControl(originalResponse.newBuilder()).build(); }).readTimeout(20000, java.util.concurrent.TimeUnit.MILLISECONDS).followRedirects(true) .followSslRedirects(true).addInterceptor(chain -> { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) { return chain.proceed(chain.request()); }//ww w. j ava 2s .co m } throw new NoConnectivityException(); }).build(); Request request = new Request.Builder().url(attachment.mUrl).build(); Response response = client.newCall(request).execute(); ResponseBody body = response.body(); if (body == null) { throw new IOException("body was null"); } try { if (!response.isSuccessful()) { throw new IOException("failed to download file: " + response.code()); } if (body.contentLength() == 0) { throw new EmptyMetadataException(attachment.mUrl); } InputStream is = body.byteStream(); OutputStream os = new BufferedOutputStream(new FileOutputStream(getAttachmentFile(context, attachment)), 4096); try { IOUtils.copy(is, os, 4096); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); response.close(); } } finally { try { response.close(); } catch (Exception ex) { // Ignore } } }
From source file:com.yelinaung.programmerexcuses.HomeActivity.java
public static boolean isOnline(Context c) { NetworkInfo netInfo = null; try {/*from ww w . j a v a2 s . c o m*/ ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); netInfo = cm.getActiveNetworkInfo(); } catch (SecurityException e) { e.printStackTrace(); } return netInfo != null && netInfo.isConnectedOrConnecting(); }
From source file:com.riksof.a320.http.CoreHttpClient.java
/** * This will check for network availability * //from w w w . j a va 2s .c o m * @param context * @return the boolean for network availability */ public static boolean isNetworkAvailable(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; } return false; }
From source file:com.dmsl.anyplace.utils.NetworkUtils.java
public static boolean haveNetworkConnection(Activity activity) { boolean haveWifi = false; boolean haveMobile = false; ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni != null && ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnectedOrConnecting()) haveWifi = true;/*from w ww. java 2 s . c o m*/ if (ni != null && ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnectedOrConnecting()) haveMobile = true; } return haveMobile || haveWifi; }
From source file:at.ac.tuwien.detlef.gpodder.PodderService.java
private static boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) Detlef.getAppContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return (netInfo != null && netInfo.isConnectedOrConnecting()); }
From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java
/** * Method to check if device is connected to the internet * @param context from which call is being made * @return true if connected, false otherwise */// w ww . j a va 2 s. co m public static boolean isOnline(Context context) { if (context != null) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); } return false; }
From source file:com.luke.lukef.lukeapp.tools.LukeUtils.java
/** * Checks the current Internet status, if Internet is not enabled then calls * {@link LukeUtils#alertDialogBuilder(Context, String, String)} to create a prompt for the user * to enable Internet./* w w w. j ava 2 s . co m*/ * * @param context Context, needed to create the alert. * @return <b>true</b> if the GPS is enabled, <b>false</b> if it's not. */ public static boolean checkInternetStatus(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; } else { alertDialogBuilder(context, noInternet, Settings.ACTION_WIRELESS_SETTINGS); return false; } }
From source file:me.zhang.bingo.Utility.java
/** * Returns true if the network is available or about to become available. * * @param c Context used to get the ConnectivityManager * @return true if the network is available *///from w w w . ja v a 2 s. c o m public static boolean isNetworkAvailable(Context c) { ConnectivityManager cm = (ConnectivityManager) c.getSystemService(CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); }