List of usage examples for android.net.wifi WifiManager getConnectionInfo
public WifiInfo getConnectionInfo()
From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java
public static String getHWID(Context cx) { if (sHWID != null) return sHWID; // If we're on SDK version > 8, use Build.SERIAL if (android.os.Build.VERSION.SDK_INT > 8) { sHWID = android.os.Build.SERIAL; }//from www .jav a 2 s . c o m if (sHWID != null) return sHWID; // Otherwise, try from the telephony manager TelephonyManager mTelephonyMgr = (TelephonyManager) cx.getSystemService(TELEPHONY_SERVICE); if (mTelephonyMgr != null) { sHWID = mTelephonyMgr.getDeviceId(); } if (sHWID != null) return sHWID; // Otherwise, try WIFI_SERVICE and use the wifi manager WifiManager wifiMan = (WifiManager) cx.getSystemService(Context.WIFI_SERVICE); if (wifiMan != null) { WifiInfo wifi = wifiMan.getConnectionInfo(); if (wifi != null) { sHWID = "wifimac" + wifi.getMacAddress(); } } if (sHWID != null) return sHWID; sHWID = "0011223344556677"; return sHWID; }
From source file:org.sipdroid.sipua.ui.Receiver.java
public static boolean isFast(int i) { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); if (PreferenceManager.getDefaultSharedPreferences(mContext) .getString(org.sipdroid.sipua.ui.Settings.PREF_USERNAME + (i != 0 ? i : ""), "").equals("") || PreferenceManager.getDefaultSharedPreferences(mContext) .getString(org.sipdroid.sipua.ui.Settings.PREF_SERVER + (i != 0 ? i : ""), "").equals("")) return false; if (wi != null) { if (!Sipdroid.release) Log.i("SipUA:", "isFastWifi() " + WifiInfo.getDetailedStateOf(wi.getSupplicantState()) + " " + wi.getIpAddress()); if (wi.getIpAddress() != 0 && (WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.OBTAINING_IPADDR || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTED) || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTING) { on_wlan = true;/*from ww w . ja v a 2s. co m*/ if (!on_vpn()) return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_WLAN + (i != 0 ? i : ""), org.sipdroid.sipua.ui.Settings.DEFAULT_WLAN); else return PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_VPN + (i != 0 ? i : ""), org.sipdroid.sipua.ui.Settings.DEFAULT_VPN); } } on_wlan = false; return isFastGSM(i); }
From source file:org.metawatch.manager.Monitors.java
private static void createWifiReceiver(final Context context) { if (wifiReceiver != null) return;/*w w w . j ava2 s .c om*/ WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wm.getConnectionInfo(); if (info != null) SignalData.wifiBars = 1 + WifiManager.calculateSignalLevel(info.getRssi(), 4); wifiReceiver = new BroadcastReceiver() { int wifiBars = 0; @Override public void onReceive(Context c, Intent intent) { String action = intent.getAction(); if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN) != WifiManager.WIFI_STATE_ENABLED) { wifiBars = 0; } } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { if (!intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) { wifiBars = 0; } } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { NetworkInfo netInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); if (netInfo.getState() != NetworkInfo.State.CONNECTED) { wifiBars = 0; } else { WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); if (wifiInfo == null) { wifiBars = 0; } else { wifiBars = 1 + WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 4); } } } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) { final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200); wifiBars = 1 + WifiManager.calculateSignalLevel(newRssi, 4); } if (wifiBars != SignalData.wifiBars) { SignalData.wifiBars = wifiBars; Idle.updateIdle(context, true); } } }; IntentFilter f = new IntentFilter(); f.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); f.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); f.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); f.addAction(WifiManager.RSSI_CHANGED_ACTION); context.registerReceiver(wifiReceiver, f); }
From source file:android_network.hetnet.vpn_service.Util.java
public static String getWifiSSID(Context context) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); String ssid = (wm == null ? null : wm.getConnectionInfo().getSSID()); return (ssid == null ? "NULL" : ssid); }
From source file:eu.faircode.netguard.Util.java
public static String getWifiSSID(Context context) { WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); String ssid = (wm == null ? null : wm.getConnectionInfo().getSSID()); return (ssid == null ? "NULL" : ssid); }
From source file:org.brandroid.openmanager.fragments.DialogHandler.java
public static String getNetworkInfo(Context c) { String ret = getNetworkInterfaces(); ConnectivityManager conman = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); if (conman == null) ret += "No Connectivity?\n"; else {//from ww w. j ava 2 s .c o m ret += "Connectivity Info:\n" + conman.toString() + "\n"; for (NetworkInfo ni : conman.getAllNetworkInfo()) { if (!ni.isAvailable()) continue; ret += "Network [" + ni.getTypeName() + "]: " + getNetworkInfoInfo(ni) + "\n"; } } try { WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); if (wifi == null) ret += "No wifi\n"; else { ret += "Wifi Info:\n" + wifi.toString() + "\n"; ret += "Status: " + (wifi.isWifiEnabled() ? "ENABLED" : "DISABLED") + "\n"; ret += "ip=" + getReadableIP(wifi.getConnectionInfo().getIpAddress()) + "/ " + "mac=" + wifi.getConnectionInfo().getMacAddress() + "/ " + "b=" + wifi.getConnectionInfo().getBSSID() + "/ " + "s=" + wifi.getConnectionInfo().getSSID(); DhcpInfo dh = wifi.getDhcpInfo(); if (dh == null) ret += "No DHCP\n"; else { ret += "IP: " + getReadableIP(dh.ipAddress) + "\n"; ret += "Gateway: " + getReadableIP(dh.gateway) + "\n"; ret += "DNS: " + getReadableIP(dh.dns1) + " " + getReadableIP(dh.dns2) + "\n"; } } } catch (SecurityException sec) { ret += "No Wifi permissions.\n"; } return ret; }
From source file:com.xdyou.sanguo.GameSanGuo.java
public static String getMacID() { String str = "mac_address"; WifiManager wifi = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); str = info.getMacAddress();/*from w w w.j a va 2 s . c o m*/ // ??imei? if (str == null) { TelephonyManager tm = (TelephonyManager) mActivity.getSystemService(TELEPHONY_SERVICE); str = tm.getDeviceId(); } Log.e("mac_address", str); return str; }
From source file:io.v.positioning.BluetoothPositionActivity.java
private void addPositionRecord(String deviceName, String deviceAddress, String rssi) { JSONObject data = new JSONObject(); // If user didn't set a device name if (deviceName == null) { deviceName = "name missing"; }//from w w w. j a v a 2s.c o m try { data.put("remoteName", deviceName); data.put("remoteAddress", deviceAddress); data.put("remoteRssi", rssi); String androidId = Settings.Secure.getString(this.getBaseContext().getContentResolver(), Settings.Secure.ANDROID_ID); data.put("androidId", androidId); WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo = wifiManager.getConnectionInfo(); data.put("myMacAddress", wInfo.getMacAddress()); data.put("deviceTime", System.currentTimeMillis()); new ServletPostAsyncTask("bluetooth", data).execute(this); Log.d(TAG, "Added " + androidId); } catch (MalformedURLException e) { Log.e(TAG, "Failed to create ServletPostAsyncTask." + e); } catch (Exception e) { Log.e(TAG, "Failed to add a record to GAE. " + e); } }
From source file:com.swisscom.safeconnect.fragment.InfoFragment.java
private String getConnectedSSID() { String ssid = null;/*from ww w . j a v a 2 s.c o m*/ ConnectivityManager connManager = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo.isConnected()) { final WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null && !TextUtils.isEmpty(connectionInfo.getSSID())) { ssid = connectionInfo.getSSID(); } } return ssid; }
From source file:org.peterbaldwin.vlcremote.app.PickServerActivity.java
private WifiInfo getConnectionInfo() { Object service = getSystemService(WIFI_SERVICE); WifiManager manager = (WifiManager) service; WifiInfo info = manager.getConnectionInfo(); if (info != null) { SupplicantState state = info.getSupplicantState(); if (state.equals(SupplicantState.COMPLETED)) { return info; }/*from w w w. j ava 2 s .c o m*/ } return null; }