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:uk.co.senab.photoview.sample.ViewPagerActivity.java
public static boolean internetIsConnected(final Activity activity) { boolean connected = false; // Get connect mangaer final ConnectivityManager connMgr = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); // check for wifi final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); // check for mobile data final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (wifi.isAvailable()) { connected = true;//from w ww . ja va2 s . c om } else if (mobile.isAvailable()) { connected = true; } else { connected = false; } return connected; }
From source file:org.uguess.android.sysinfo.SiragonManager.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final Activity ctx = getActivity(); if (item.getItemId() == MI_PREFERENCE) { Intent it = new Intent(ctx, InfoSettings.class); it.putExtra(PREF_KEY_SHOW_INFO_ICON, Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_SHOW_INFO_ICON)); it.putExtra(PREF_KEY_SHOW_TASK_ICON, Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_SHOW_TASK_ICON)); it.putExtra(PREF_KEY_AUTO_START_ICON, Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_AUTO_START_ICON, false)); it.putExtra(PREF_KEY_DEFAULT_SERVER, Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_SERVER, null)); it.putExtra(PREF_KEY_DEFAULT_EMAIL, Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_EMAIL, null)); it.putExtra(PREF_KEY_DEFAULT_TAB, Util.getIntOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_TAB, 0)); it.putExtra(PREF_KEY_WIDGET_DISABLED, Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_WIDGET_DISABLED, null)); startActivityForResult(it, 2);//from w ww .jav a2 s .c o m return true; } else if (item.getItemId() == MI_HELP) { Intent it = new Intent(Intent.ACTION_VIEW); String target = "http://www.siragon.com.ve"; //$NON-NLS-1$ ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (info != null && info.isConnected()) { target = "http://www.siragon.com.ve"; //$NON-NLS-1$ } it.setData(Uri.parse(target)); it = Intent.createChooser(it, null); startActivity(it); return true; } ///////////////////////PATH SERVER/////////////////////////////////// else if (item.getItemId() == MI_ABOUT) { ScrollView sv = new ScrollView(ctx); TextView txt = new TextView(ctx); txt.setGravity(Gravity.CENTER_HORIZONTAL); txt.setTextAppearance(ctx, android.R.style.TextAppearance_Medium); sv.addView(txt); String href = "http://www.google.com.ve"; //$NON-NLS-1$ txt.setText(Html.fromHtml(getString(R.string.about_msg, getVersionName(ctx.getPackageManager(), ctx.getPackageName()), href))); txt.setMovementMethod(LinkMovementMethod.getInstance()); new AlertDialog.Builder(ctx).setTitle(R.string.app_name).setIcon(R.drawable.logo2).setView(sv) .setNegativeButton(R.string.close, null).create().show(); return true; } else if (item.getItemId() == MI_EXIT) { OnClickListener listener = new OnClickListener() { public void onClick(DialogInterface dialog, int which) { Util.killSelf(handler, ctx, (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE), ctx.getPackageName()); } }; new AlertDialog.Builder(ctx).setTitle(R.string.prompt).setMessage(R.string.exit_prompt) .setPositiveButton(android.R.string.yes, listener).setNegativeButton(android.R.string.no, null) .create().show(); return true; } else if (item.getItemId() == MI_REFRESH) { updateInfo(); return true; } return false; }
From source file:com.grazerss.EntryManager.java
boolean isOnWiFi() { if (connectivityManager == null) { connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); }/* ww w . j a v a2s . c om*/ if (connectivityManager == null) { PL.log("EntryManager. Wasn't able to get CONNECTIVITY_SERVICE.", ctx); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { PL.log("WiFi Info=" + wifiInfo + " SSID=" + wifiInfo.getSSID(), ctx); } return false; } final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { PL.log("EntryManager. Wasn't able to get Network Info.", ctx); return false; } if (ConnectivityManager.TYPE_WIFI != networkInfo.getType()) { PL.log("EntryManager. Network Info Type was not WiFi, but " + networkInfo.getType() + ".", ctx); return false; } return true; }
From source file:com.newsrob.EntryManager.java
boolean isOnWiFi() { if (connectivityManager == null) connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { PL.log("EntryManager. Wasn't able to get CONNECTIVITY_SERVICE.", ctx); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) PL.log("WiFi Info=" + wifiInfo + " SSID=" + wifiInfo.getSSID(), ctx); return false; }//from w ww . j a v a 2s . c om final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { PL.log("EntryManager. Wasn't able to get Network Info.", ctx); return false; } if (ConnectivityManager.TYPE_WIFI != networkInfo.getType()) { PL.log("EntryManager. Network Info Type was not WiFi, but " + networkInfo.getType() + ".", ctx); return false; } return true; }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
/** * /*from w w w. ja v a2 s .co m*/ * @param context * @return */ public static boolean isNetworkAvailable(Context context) { boolean isMobile = false, isWifi = false; try { NetworkInfo[] infoAvailableNetworks = ((ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE)).getAllNetworkInfo(); if (infoAvailableNetworks != null) { for (NetworkInfo network : infoAvailableNetworks) { if (network.getType() == ConnectivityManager.TYPE_WIFI) { if (network.isConnected() && network.isAvailable()) isWifi = true; } if (network.getType() == ConnectivityManager.TYPE_MOBILE) { if (network.isConnected() && network.isAvailable()) isMobile = true; } } } return isMobile || isWifi; } catch (Exception e) { return false; } }
From source file:com.ferdi2005.secondgram.voip.VoIPService.java
private void updateNetworkType() { ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); lastNetInfo = info;// w w w . j a va 2 s . c o m int type = VoIPController.NET_TYPE_UNKNOWN; if (info != null) { switch (info.getType()) { case ConnectivityManager.TYPE_MOBILE: switch (info.getSubtype()) { case TelephonyManager.NETWORK_TYPE_GPRS: type = VoIPController.NET_TYPE_GPRS; break; case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_1xRTT: type = VoIPController.NET_TYPE_EDGE; break; case TelephonyManager.NETWORK_TYPE_UMTS: case TelephonyManager.NETWORK_TYPE_EVDO_0: type = VoIPController.NET_TYPE_3G; break; case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_HSPAP: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_EVDO_B: type = VoIPController.NET_TYPE_HSPA; break; case TelephonyManager.NETWORK_TYPE_LTE: type = VoIPController.NET_TYPE_LTE; break; default: type = VoIPController.NET_TYPE_OTHER_MOBILE; break; } break; case ConnectivityManager.TYPE_WIFI: type = VoIPController.NET_TYPE_WIFI; break; case ConnectivityManager.TYPE_ETHERNET: type = VoIPController.NET_TYPE_ETHERNET; break; } } if (controller != null) { controller.setNetworkType(type); } }
From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java
private void processNetworkType(Intent intent, Context context) { int netType;/*from w w w.j av a 2s . com*/ int netSubtype; int networkType; boolean isConnected; String reloadUrl; DebugLog.d(TAG, "processNetworkType() enter"); NetworkInfo netInfo = Utils.getCurNetworkInfo(context); if (netInfo == null || netInfo.isAvailable() == false) { DebugLog.d(TAG, "getCurNetworkInfo() is null"); netInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); } if (netInfo == null || netInfo.isAvailable() == false) { DebugLog.d(TAG, "getCurNetworkInfo() netInfo is null line1383"); if (mbNetworIsConnect != false) { mbNetworIsConnect = false; reloadUrl = GameInfo.getErrorUrl(); reload(reloadUrl); } Utils.setNetworkType(Constants.NETWORKTYPE_NONE); return; } netType = netInfo.getType(); netSubtype = netInfo.getSubtype(); isConnected = netInfo.isConnected(); DebugLog.e(TAG, "======processNetworkType nettype = " + netType + ",netSubtype = " + netSubtype + ",isConnect = " + isConnected); switch (netType) { case ConnectivityManager.TYPE_MOBILE_SUPL: case ConnectivityManager.TYPE_MOBILE_MMS: case ConnectivityManager.TYPE_MOBILE_HIPRI: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE: DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE netSubtype=" + netSubtype); if (netSubtype == TelephonyManager.NETWORK_TYPE_LTE) {//4 DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE 4G"); networkType = Constants.NETWORKTYPE_LTE; } else {//3 DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_MOBILE 3G"); networkType = Constants.NETWORKTYPE_3G; } break; case ConnectivityManager.TYPE_WIFI: DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_WIFI"); networkType = Constants.NETWORKTYPE_WIFI; break; case ConnectivityManager.TYPE_ETHERNET: DebugLog.d(TAG, "processNetworkType ConnectivityManager.TYPE_ETHERNET"); networkType = Constants.NETWORKTYPE_ETHERNET; break; default: DebugLog.d(TAG, "other network status"); networkType = Constants.NETWORKTYPE_OTHERS; break; } DebugLog.e(TAG, "======processNetworkType nettype = " + netType + ",netSubtype = " + netSubtype + ",isConnect = " + isConnected + ",mbNetworIsConnect = " + mbNetworIsConnect); if (isConnected) { reloadUrl = Utils.checkUrl(GameInfo.DEFAULT_URL); Utils.setNetworkType(networkType); // Utils.setNetworkType(Constants.NETWORKTYPE_WIFI);//temp change } else { reloadUrl = GameInfo.getErrorUrl(); Utils.setNetworkType(Constants.NETWORKTYPE_NONE); } // if((networkType == Constants.NETWORKTYPE_WIFI || networkType == Constants.NETWORKTYPE_LTE) && mbNetworIsConnect != isConnected){ if (mbNetworIsConnect != isConnected) { mbNetworIsConnect = isConnected; reload(reloadUrl); DebugLog.d(TAG, "Notify reload finish"); } }
From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java
protected int getConnectionType() { int newState = mNetworkInfo.getType(); if (LOCAL_LOGV) { String str = ""; switch (newState) { case ConnectivityManager.TYPE_WIFI: str += "wifi"; break; case ConnectivityManager.TYPE_MOBILE: str += "mobile"; break; case ConnectivityManager.TYPE_MOBILE_DUN: str += "mobile-dun"; break; case ConnectivityManager.TYPE_MOBILE_HIPRI: str += "moblie-hipri"; break; case ConnectivityManager.TYPE_MOBILE_MMS: str += "mobile-mms"; break; case ConnectivityManager.TYPE_MOBILE_SUPL: str += "mobile-supl"; break; case ConnectivityManager.TYPE_WIMAX: str += "wimax"; break; case ConnectivityManager.TYPE_ETHERNET: str += "ethernet"; break; case ConnectivityManager.TYPE_BLUETOOTH: str += "bluetooth"; break; case ConnectivityManager.TYPE_DUMMY: str += "dummy"; break; }//w w w . j ava 2s .c o m str += " detected"; log(str, "v"); } return newState; }
From source file:com.sonetel.ui.dialpad.DialerFragment.java
protected boolean isInternetAvail(Context context) { connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = connectivityManager.getActiveNetworkInfo(); if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) { Log.d(THIS_FILE, "Wifi state is now " + ni.getState().name()); if (ni.getState() == NetworkInfo.State.CONNECTED) { return true; }//from w ww. jav a 2s . c o m } if (ni != null && ni.getType() == ConnectivityManager.TYPE_MOBILE) { // Any mobile network connected if (ni.getState() == NetworkInfo.State.CONNECTED) { int subType = ni.getSubtype(); // 3G (or better) if (subType >= TelephonyManager.NETWORK_TYPE_UMTS) { return true; } // GPRS (or unknown) if (subType == TelephonyManager.NETWORK_TYPE_GPRS || subType == TelephonyManager.NETWORK_TYPE_UNKNOWN) { return true; } // EDGE if (subType == TelephonyManager.NETWORK_TYPE_EDGE) { return true; } } } if (ni != null && ni.getType() != ConnectivityManager.TYPE_MOBILE && ni.getType() != ConnectivityManager.TYPE_WIFI) { if (ni.getState() == NetworkInfo.State.CONNECTED) { return true; } } return false; }
From source file:ua.mkh.weather.MainActivity.java
public boolean low_mode_check() { boolean state = true; boolean state_brightness = true; boolean state_wifi = true; boolean state_bt = true; int status = Settings.System.getInt(getContentResolver(), "screen_brightness_mode", 0); if (status == 1) { state_brightness = false;// w ww. j a v a2s .com } //0 // ContentResolver cResolver = getContentResolver(); int brightness = 0; try { //Get the current system brightness brightness = System.getInt(cResolver, System.SCREEN_BRIGHTNESS); } catch (SettingNotFoundException e) { //Throw an error case it couldn't be retrieved Log.e("Error", "Cannot access system brightness"); e.printStackTrace(); } if (brightness > 25) { state_brightness = false; } //WIFI ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifi.isWifiEnabled()) { if (mWifi.isConnected()) { } else { state_wifi = false; } } //Bluetooth BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter.isEnabled()) { state_bt = false; } if (state_brightness == false || state_wifi == false || state_bt == false) { state = false; } return state; }