List of usage examples for android.net NetworkInfo isConnectedOrConnecting
@Deprecated public boolean isConnectedOrConnecting()
From source file:us.dustinj.locationstore.LocationService.java
public boolean IsNetworkConnected() { NetworkInfo info = m_connectivityManager.getActiveNetworkInfo(); boolean connected = info != null && info.isConnectedOrConnecting(); Log.d(this.getClass().getSimpleName(), "IsNetworkConnected - canGetInfo: " + (info != null ? "True" : "False") + " connected: " + (connected ? "True" : "False")); return connected; }
From source file:fi.aalto.displayingbitmaps.util.ImageFetcher.java
/** * Simple network connection check.//from w w w. j ava2 s . 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, R.string.no_network_connection_toast, Toast.LENGTH_LONG).show(); Log.e(TAG, "checkConnection - no connection found"); } }
From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java
public boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); }
From source file:uk.ac.horizon.aestheticodes.controllers.ExperienceListUpdater.java
@Override protected Collection<String> doInBackground(Void... params) { final Gson gson = ExperienceParser.createParser(); Set<String> removals = new HashSet<>(); try {//w w w .j a v a2s. c om Collection<Experience> experienceList = experiences.get(); boolean loaded = false; if (experienceList.isEmpty()) { Log.i("", "Loading..."); try { Experience[] experiencesLoaded = null; File experienceFile = new File(context.getFilesDir(), "experiences.json"); if (experienceFile.exists()) { try { Log.i("", "Loading " + experienceFile.getAbsolutePath()); experiencesLoaded = gson.fromJson(new FileReader(experienceFile), Experience[].class); } catch (Exception e) { Log.w("", e.getMessage(), e); } } if (experiencesLoaded == null) { Log.i("", "Loading default.json"); experiencesLoaded = gson.fromJson( new InputStreamReader(context.getAssets().open("default.json")), Experience[].class); } if (experiencesLoaded != null) { Log.i("", "Loaded"); publishProgress(experiencesLoaded); experienceList = Arrays.asList(experiencesLoaded); } loaded = true; } catch (Exception e) { Log.w(TAG, "Failed to load settings", e); } } Log.i(TAG, "Updating..."); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { boolean changes = false; final ExperienceUpdates updates = new ExperienceUpdates(); for (Experience experience : experienceList) { Log.i("", experience.getId()); if (experience.getOp() == null || experience.getOp() == Experience.Operation.retrieve) { updates.experiences.add(new ExperienceOp(experience.getId(), experience.getVersion())); } else if (experience.getOp() == Experience.Operation.remove) { updates.experiences.add(new ExperienceOp(experience.getId(), Experience.Operation.remove)); changes = true; } else if (experience.getOp() != Experience.Operation.temp) { updates.experiences.add(experience); changes = true; } } if (changes || loaded) { HttpResponse response = put( "https://aestheticodes.appspot.com/_ah/api/experiences/v1/experiences", gson.toJson(updates)); if (response.getStatusLine().getStatusCode() == 200) { ExperienceResults results = gson.fromJson( new InputStreamReader(response.getEntity().getContent()), ExperienceResults.class); for (String experienceID : results.experiences.keySet()) { Experience experience = results.experiences.get(experienceID); if (experience.getId() == null) { experience.setId(experienceID); } if (!experienceID.equals(experience.getId())) { publishProgress(experience); removals.add(experienceID); } else if (experience.getOp() == Experience.Operation.remove) { removals.add(experience.getId()); } else { publishProgress(experience); } } } } } } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } return removals; }
From source file:edu.berkeley.boinc.attach.AcctMgrFragment.java
private Boolean checkDeviceOnline() { ConnectivityManager connectivityManager = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); Boolean online = activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting(); if (!online) { Toast toast = Toast.makeText(getActivity(), R.string.attachproject_list_no_internet, Toast.LENGTH_SHORT);//from w w w .j a va 2 s . c om toast.show(); if (Logging.DEBUG) Log.d(Logging.TAG, "AttachProjectListActivity not online, stop!"); } return online; }
From source file:org.zywx.wbpalmstar.platform.push.mqttpush.PushGetData.java
private void onReceive() { final String CONNECTIVITY_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); filter.addAction(CONNECTIVITY_CHANGE_ACTION); if (myBroadcastReceiver == null) { myBroadcastReceiver = new BroadcastReceiver() { @Override// w w w .ja va 2 s .c o m public void onReceive(Context context, Intent intent) { if ("android.intent.action.SCREEN_OFF".equals(intent.getAction())) { if (isTemporary) { sleepTime = 1000 * 60 * 2; } else { sleepTime = 1000 * 60 * 15; } notifiTimer(); } else if ("android.intent.action.SCREEN_ON".equals(intent.getAction())) { if (isTemporary) { sleepTime = 1000 * 30; } else { sleepTime = 1000 * 60 * 2; } // notifiTimer(); } if (TextUtils.equals(intent.getAction(), CONNECTIVITY_CHANGE_ACTION)) { ConnectivityManager mConnMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (mConnMgr != null) { NetworkInfo aActiveInfo = mConnMgr.getActiveNetworkInfo(); // ?? if (!isNotify && aActiveInfo != null && aActiveInfo.isConnectedOrConnecting()) { init(); isNotify = true; } else { isNotify = false; stop(false); } } else { isNotify = false; stop(false); } } } }; } mCtx.registerReceiver(myBroadcastReceiver, filter); }
From source file:de.awisus.refugeeaidleipzig.MainActivity.java
private boolean connected() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivityManager.getActiveNetworkInfo(); return nwInfo != null && nwInfo.isConnectedOrConnecting(); }
From source file:org.zywx.wbpalmstar.platform.push.mqttpush.PushGetData2.java
private void onReceive() { final String CONNECTIVITY_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; IntentFilter filter = new IntentFilter(); filter.addAction(CONNECTIVITY_CHANGE_ACTION); if (myBroadcastReceiver == null) { myBroadcastReceiver = new BroadcastReceiver() { @Override// www . j a va2 s .c o m public void onReceive(Context context, Intent intent) { if (TextUtils.equals(intent.getAction(), CONNECTIVITY_CHANGE_ACTION)) { ConnectivityManager mConnMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (mConnMgr != null) { NetworkInfo aActiveInfo = mConnMgr.getActiveNetworkInfo(); // ?? if (!isNotify && aActiveInfo != null && aActiveInfo.isConnectedOrConnecting()) { init(); isNotify = true; } else if (aActiveInfo == null) { isNotify = false; System.out.println("broker? stop 1"); stop(false); } } else { isNotify = false; stop(false); System.out.println("broker? stop 2"); } } } }; } mCtx.registerReceiver(myBroadcastReceiver, filter); }
From source file:net.xisberto.phonetodesktop.network.GoogleTasksService.java
private boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; }/* www .j av a 2 s. c om*/ return false; }
From source file:edu.berkeley.boinc.attach.SelectionListActivity.java
private Boolean checkDeviceOnline() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); Boolean online = activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting(); if (!online) { Toast toast = Toast.makeText(getApplicationContext(), R.string.attachproject_list_no_internet, Toast.LENGTH_SHORT);// w w w . ja va 2s. c o m toast.show(); if (Logging.DEBUG) Log.d(Logging.TAG, "AttachProjectListActivity not online, stop!"); } return online; }