List of usage examples for android.net ConnectivityManager TYPE_WIFI
int TYPE_WIFI
To view the source code for android.net ConnectivityManager TYPE_WIFI.
Click Source Link
From source file:util.Utils.java
/** * ?wifi?/* w w w . ja v a2s.com*/ * @param context * @return true WiFifalse ?WiFi */ public static boolean getWIFIConnectStatus(Context context) { ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); return mWifi.isConnected(); }
From source file:free.yhc.feeder.model.Utils.java
/** * Is any available active network at this device? * @return//from w w w . j a va 2 s.c o m */ public static boolean isNetworkAvailable() { ConnectivityManager cm = (ConnectivityManager) Environ.getAppContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni; if (isPrefUseWifiOnly()) ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); else ni = cm.getActiveNetworkInfo(); if (null != ni) return ni.isConnectedOrConnecting(); else return false; }
From source file:com.zhongsou.souyue.activity.SplashActivity.java
protected boolean parseNetStatus(NetworkInfo ni) { if (ni == null) throw new RuntimeException("ni can not be null"); if (highSpeed.contains(ni.getSubtype()) || ni.getType() == ConnectivityManager.TYPE_WIFI) return true; return false; }
From source file:fr.kwiatkowski.apktrack.service.WebService.java
/** * Checks whether the check should be aborted. * This may happen depending on user preferences (i.e. WiFi only) * @return True if the check should be cancelled. *///from www .j a v a 2s. c o m private boolean _check_cancellation() { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); // If the background checks are not allowed, abort. if (!pref.getBoolean(SettingsFragment.KEY_PREF_BACKGROUND_CHECKS, false)) { return true; } // If the user requested it, verify that we are using WiFi before each request. if (pref.getBoolean(SettingsFragment.KEY_PREF_WIFI_ONLY, true)) { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); if (info == null) { Log.v(MainActivity.TAG, "Aborting automatic checks because no network is currently active."); return true; } else if (info.getType() != ConnectivityManager.TYPE_WIFI) { Log.v(MainActivity.TAG, "Aborting automatic checks over data due to user preferences."); return true; } } return false; }
From source file:com.dwdesign.tweetings.activity.HomeActivity.java
public void connectToStream() { if (mPreferences.getBoolean(PREFERENCE_KEY_STREAMING_ENABLED, false) == true) { if (mService != null && twitterStream != null) { try { // user() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null) { if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) { hasStreamLoaded = true; twitterStream.user(); if (mPreferences.getBoolean(PREFERENCE_KEY_STREAMING_NOTIFICATION, false) == true) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); final Intent intent = new Intent(this, HomeActivity.class); final Notification.Builder builder = new Notification.Builder(this); builder.setOngoing(true); builder.setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setSmallIcon(R.drawable.ic_launcher); builder.setContentTitle(getString(R.string.app_name)); builder.setContentText(getString(R.string.streaming_service_running)); builder.setTicker(getString(R.string.streaming_service_running)); notificationManager.notify(NOTIFICATION_ID_STREAMING, builder.build()); }/*from w ww . ja v a2 s . c o m*/ } } } catch (final Exception e) { e.printStackTrace(); } } } }
From source file:com.z3r0byte.magistify.Services.OldBackgroundService.java
private Boolean usingWifi() { final ConnectivityManager connMgr = (ConnectivityManager) this .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = connMgr.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI; }
From source file:de.tap.easy_xkcd.utils.PrefHelper.java
public boolean isWifi(Context context) { if (context == null) { Log.e("error", "context null"); return true; }//from w w w. j a va 2 s. c o m ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI); }
From source file:at.alladin.rmbt.android.util.InformationCollector.java
/** Returns the network that the phone is on (e.g. Wifi, Edge, GPRS, etc). */ public int getNetwork() { int result = TelephonyManager.NETWORK_TYPE_UNKNOWN; if (connManager != null) { final NetworkInfo activeNetworkInfo = connManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { final int type = activeNetworkInfo.getType(); switch (type) { case ConnectivityManager.TYPE_WIFI: result = NETWORK_WIFI;//from w ww.ja va 2s . c o m break; case ConnectivityManager.TYPE_BLUETOOTH: result = NETWORK_BLUETOOTH; break; case ConnectivityManager.TYPE_ETHERNET: result = NETWORK_ETHERNET; break; case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_HIPRI: case ConnectivityManager.TYPE_MOBILE_MMS: case ConnectivityManager.TYPE_MOBILE_SUPL: result = telManager.getNetworkType(); break; } } } /* detect change from wifi to mobile or reverse */ final int lastNetworkType = this.lastNetworkType.get(); if (result != TelephonyManager.NETWORK_TYPE_UNKNOWN && lastNetworkType != TelephonyManager.NETWORK_TYPE_UNKNOWN) { if ((result == ConnectivityManager.TYPE_WIFI && lastNetworkType != ConnectivityManager.TYPE_WIFI) || (result != ConnectivityManager.TYPE_WIFI && lastNetworkType == ConnectivityManager.TYPE_WIFI)) illegalNetworkTypeChangeDetcted.set(true); } if (result != lastNetworkType) { this.lastNetworkType.set(result); if (telListener != null) telListener.onSignalStrengthsChanged(null); } return result; }
From source file:org.restcomm.app.utillib.Reporters.WebReporter.WebReporter.java
/** * @return true if the current connected network is wifi *//*from w w w.j a va 2 s .com*/ protected boolean isNetworkWifi() { ConnectivityManager connectivityManager = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager != null) { NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { int wifiState = networkInfo.getType(); return (wifiState == ConnectivityManager.TYPE_WIFI); } } return false; }
From source file:org.pixmob.freemobile.netstat.MonitorService.java
/** * This method is called when the phone data connectivity is updated. *///from w w w . j ava 2s. c o m private boolean onConnectivityUpdated() { // Get the Wi-Fi connectivity state. final NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final boolean wifiNetworkConnected = ni != null && ni.isConnected(); // Prevent duplicated inserts. if (lastWifiConnected != null && lastWifiConnected == wifiNetworkConnected) { return false; } lastWifiConnected = wifiNetworkConnected; Log.i(TAG, "Wifi state updated: connected=" + wifiNetworkConnected); return true; }