Java Code Examples for android.net.wifi.WifiInfo#getBSSID()
The following examples show how to use
android.net.wifi.WifiInfo#getBSSID() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkKey.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Constructs a new NetworkKey for the given {@link WifiInfo}. * * @param wifiInfo the {@link WifiInfo} to create a {@link NetworkKey} for. * @return A new {@link NetworkKey} instance or <code>null</code> if the given {@link WifiInfo} * instance doesn't represent a connected WiFi network. * @hide */ @Nullable public static NetworkKey createFromWifiInfo(@Nullable WifiInfo wifiInfo) { if (wifiInfo != null) { final String ssid = wifiInfo.getSSID(); final String bssid = wifiInfo.getBSSID(); if (!TextUtils.isEmpty(ssid) && !ssid.equals(WifiSsid.NONE) && !TextUtils.isEmpty(bssid)) { WifiKey wifiKey; try { wifiKey = new WifiKey(ssid, bssid); } catch (IllegalArgumentException e) { Log.e(TAG, "Unable to create WifiKey.", e); return null; } return new NetworkKey(wifiKey); } } return null; }
Example 2
Source File: WifiWizard.java From WifiWizard with Apache License 2.0 | 6 votes |
/** * This method retrieves the SSID for the currently connected network * * @param callbackContext A Cordova callback context * @return true if SSID found, false if not. */ private boolean getConnectedSSID(CallbackContext callbackContext){ if(!wifiManager.isWifiEnabled()){ callbackContext.error("Wifi is disabled"); return false; } WifiInfo info = wifiManager.getConnectionInfo(); if(info == null){ callbackContext.error("Unable to read wifi info"); return false; } String ssid = info.getSSID(); if(ssid.isEmpty()) { ssid = info.getBSSID(); } if(ssid.isEmpty()){ callbackContext.error("SSID is empty"); return false; } callbackContext.success(ssid); return true; }
Example 3
Source File: ManageReposActivity.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
private void checkIfNewRepoOnSameWifi(NewRepoConfig newRepo) { // if this is a local repo, check we're on the same wifi if (!TextUtils.isEmpty(newRepo.getBssid())) { WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String bssid = wifiInfo.getBSSID(); if (TextUtils.isEmpty(bssid)) { /* not all devices have wifi */ return; } bssid = bssid.toLowerCase(Locale.ENGLISH); String newRepoBssid = Uri.decode(newRepo.getBssid()).toLowerCase(Locale.ENGLISH); if (!bssid.equals(newRepoBssid)) { String msg = getString(R.string.not_on_same_wifi, newRepo.getSsid()); Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); } // TODO we should help the user to the right thing here, // instead of just showing a message! } }
Example 4
Source File: PlatformNetworksManager.java From 365browser with Apache License 2.0 | 6 votes |
static VisibleWifi getConnectedWifi(Context context, WifiManager wifiManager) { if (!hasLocationAndWifiPermission(context)) { return VisibleWifi.NO_WIFI_INFO; } WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo == null) { return VisibleWifi.NO_WIFI_INFO; } String ssid = wifiInfo.getSSID(); if (ssid == null || UNKNOWN_SSID.equals(ssid)) { // No SSID. ssid = null; } else { // Remove double quotation if ssid has double quotation. if (ssid.startsWith("\"") && ssid.endsWith("\"") && ssid.length() > 2) { ssid = ssid.substring(1, ssid.length() - 1); } } String bssid = wifiInfo.getBSSID(); // It's connected, so use current time. return VisibleWifi.create(ssid, bssid, null, sTimeProvider.getCurrentTime()); }
Example 5
Source File: UENavigationActivity.java From Auie with GNU General Public License v2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { WifiInfo info = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo(); if (info.getBSSID() == null) { mNavigationView.hideWIFI(); }else { mNavigationView.showWIFI(); mNavigationView.setWIFI(WifiManager.calculateSignalLevel(info.getRssi(), 5)); } }
Example 6
Source File: UENavigationFragmentActivity.java From Auie with GNU General Public License v2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { WifiInfo info = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo(); if (info.getBSSID() == null) { mNavigationView.hideWIFI(); }else { mNavigationView.showWIFI(); mNavigationView.setWIFI(WifiManager.calculateSignalLevel(info.getRssi(), 5)); } }
Example 7
Source File: InformationFieldsFactory.java From openlocate-android with MIT License | 5 votes |
private void updateWifiInfo() { WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { wifiSsid = wifiInfo.getSSID(); wifiBssid = wifiInfo.getBSSID(); }; } }
Example 8
Source File: EasyNetworkMod.java From easydeviceinfo with Apache License 2.0 | 5 votes |
/** * Gets BSSID of Connected WiFi * * You need to declare the below permission in the manifest file to use this properly * * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> * <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> * * @return Return the basic service set identifier (BSSID) of the current access point. */ @RequiresPermission(allOf = { Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.ACCESS_NETWORK_STATE }) public final String getWifiBSSID() { String result = null; if (PermissionUtil.hasPermission(context, Manifest.permission.ACCESS_WIFI_STATE)) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo == null) { result = null; } if (networkInfo != null && networkInfo.isConnected()) { final WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null && !TextUtils.isEmpty(connectionInfo.getSSID())) { result = connectionInfo.getBSSID(); } } } } } return CheckValidityUtil.checkValidData(result); }
Example 9
Source File: Utils.java From Easer with GNU General Public License v3.0 | 5 votes |
static boolean compare(WifiUSourceData data, @NonNull WifiInfo wifiInfo) { String ssid; if (data.mode_essid) { ssid = wifiInfo.getSSID(); if (ssid.startsWith("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } } else { ssid = wifiInfo.getBSSID(); } return data.match(ssid); }
Example 10
Source File: AndroidWifiModule.java From react-native-android-wifi with ISC License | 5 votes |
@ReactMethod public void getBSSID(final Callback callback) { WifiInfo info = wifi.getConnectionInfo(); String bssid = info.getBSSID(); callback.invoke(bssid.toUpperCase()); }
Example 11
Source File: DeviceUtils.java From DoraemonKit with Apache License 2.0 | 5 votes |
/** * @return 手机链接wifi的路由器的mac地址 */ public static String getWifiBSSID(Context context) { WifiManager mWifi = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (mWifi.isWifiEnabled()) { WifiInfo wifiInfo = mWifi.getConnectionInfo(); return wifiInfo.getBSSID(); } return ""; }
Example 12
Source File: TitleView.java From android-tv-launcher with MIT License | 5 votes |
@Override public void onReceive(Context context, Intent intent) { WifiManager wifiManager = (WifiManager) context .getSystemService(context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo.getBSSID() != null) { // wifi信号强度 int signalLevel = WifiManager.calculateSignalLevel( wifiInfo.getRssi(), 4); if (signalLevel == 0) { imgNetWorkState.setImageDrawable(context.getResources() .getDrawable(R.drawable.wifi_1)); } else if (signalLevel == 1) { imgNetWorkState.setImageDrawable(context.getResources() .getDrawable(R.drawable.wifi_2)); } else if (signalLevel == 2) { imgNetWorkState.setImageDrawable(context.getResources() .getDrawable(R.drawable.wifi_3)); } else if (signalLevel == 3) { imgNetWorkState.setImageDrawable(context.getResources() .getDrawable(R.drawable.networkstate_on)); } if (d) Toast.makeText(context, "wifi level" + signalLevel, Toast.LENGTH_SHORT).show(); } }
Example 13
Source File: Transformer.java From WiFiAnalyzer with GNU General Public License v3.0 | 5 votes |
@NonNull WiFiConnection transformWifiInfo(WifiInfo wifiInfo) { if (wifiInfo == null || wifiInfo.getNetworkId() == -1) { return WiFiConnection.EMPTY; } return new WiFiConnection( WiFiUtils.convertSSID(wifiInfo.getSSID()), wifiInfo.getBSSID(), WiFiUtils.convertIpAddress(wifiInfo.getIpAddress()), wifiInfo.getLinkSpeed()); }
Example 14
Source File: RNWifiModule.java From react-native-wifi-reborn with ISC License | 5 votes |
/** * Returns the BSSID (basic service set identifier) of the currently connected WiFi network. */ @ReactMethod public void getBSSID(final Promise promise) { final WifiInfo info = wifi.getConnectionInfo(); final String bssid = info.getBSSID(); promise.resolve(bssid.toUpperCase()); }
Example 15
Source File: j.java From letv with Apache License 2.0 | 4 votes |
private List<k> d() { z.a(); if (!a()) { return new ArrayList(); } k kVar; WifiInfo connectionInfo = this.a.getConnectionInfo(); if (connectionInfo != null) { k kVar2 = new k(this, connectionInfo.getBSSID(), connectionInfo.getRssi(), connectionInfo.getSSID()); new StringBuilder(z[6]).append(kVar2.toString()); kVar = kVar2; z.a(); } else { kVar = null; } ArrayList arrayList = new ArrayList(); if (kVar != null) { arrayList.add(kVar); } List scanResults = VERSION.SDK_INT < 23 ? this.a.getScanResults() : (this.b == null || !a.c(this.b, z[5])) ? null : this.a.getScanResults(); if (r0 != null && r0.size() > 0) { int i = -200; k kVar3 = null; for (ScanResult kVar4 : r0) { int i2; k kVar5 = new k(this, kVar4); if (kVar5.c.equals(kVar.c) || kVar5.b <= i) { kVar2 = kVar3; i2 = i; } else { new StringBuilder(z[4]).append(kVar5.toString()); z.a(); k kVar6 = kVar5; i2 = kVar5.b; kVar2 = kVar6; } kVar3 = kVar2; i = i2; } if (kVar3 != null) { arrayList.add(kVar3); } } return arrayList; }
Example 16
Source File: Fingerprint.java From Inspeckage with Apache License 2.0 | 4 votes |
public static void load() { FingerprintList list = new FingerprintList(); List<FingerprintItem> li = new ArrayList<>(); String ads_id = mPrefs.getString(Config.SP_ADS_ID, ""); li.add(new FingerprintItem("Advertising", "ID", ads_id, ads_id, false)); String mac = getMacAddress(mContext); li.add(new FingerprintItem("Wi-Fi", "Android", mac, mac, false)); WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wifiManager.getConnectionInfo(); String bssid = wi.getBSSID(); li.add(new FingerprintItem("Wi-Fi", "BSSID", bssid, bssid, false)); String ssid = wi.getSSID(); li.add(new FingerprintItem("Wi-Fi", "SSID", ssid.substring(1, ssid.length() - 1), ssid.substring(1, ssid.length() - 1), false)); String ipAddress = Formatter.formatIpAddress(wi.getIpAddress()); li.add(new FingerprintItem("Wi-Fi", "IP", ipAddress, ipAddress, false)); TelephonyManager mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); li.add(new FingerprintItem("TelephonyManager", "IMEI", mTelephonyManager.getDeviceId(), mTelephonyManager.getDeviceId(), false)); li.add(new FingerprintItem("TelephonyManager", "IMSI", mTelephonyManager.getSubscriberId(), mTelephonyManager.getSubscriberId(), false)); li.add(new FingerprintItem("TelephonyManager", "PhoneNumber", mTelephonyManager.getLine1Number(), mTelephonyManager.getLine1Number(), false)); li.add(new FingerprintItem("TelephonyManager", "SimSerial", mTelephonyManager.getSimSerialNumber(), mTelephonyManager.getSimSerialNumber(), false)); li.add(new FingerprintItem("TelephonyManager", "CarrierCode", mTelephonyManager.getNetworkOperator(), mTelephonyManager.getNetworkOperator(), false)); li.add(new FingerprintItem("TelephonyManager", "Carrier", mTelephonyManager.getNetworkOperatorName(), mTelephonyManager.getNetworkOperatorName(), false)); li.add(new FingerprintItem("TelephonyManager", "SimCountry", mTelephonyManager.getSimCountryIso(), mTelephonyManager.getSimCountryIso(), false)); li.add(new FingerprintItem("TelephonyManager", "NetworkCountry", mTelephonyManager.getNetworkCountryIso(), mTelephonyManager.getNetworkCountryIso(), false)); li.add(new FingerprintItem("TelephonyManager", "SimSerialNumber", mTelephonyManager.getSimSerialNumber(), mTelephonyManager.getSimSerialNumber(), false)); li.add(new FingerprintItem("VERSION", "RELEASE", Build.VERSION.RELEASE, Build.VERSION.RELEASE, false)); li.add(new FingerprintItem("VERSION", "CODENAME", Build.VERSION.CODENAME, Build.VERSION.CODENAME, false)); li.add(new FingerprintItem("VERSION", "INCREMENTAL", Build.VERSION.INCREMENTAL, Build.VERSION.INCREMENTAL, false)); li.add(new FingerprintItem("VERSION", "SDK", Build.VERSION.SDK, Build.VERSION.SDK, false)); li.add(new FingerprintItem("VERSION", "SDK_INT", String.valueOf(Build.VERSION.SDK_INT), String.valueOf(Build.VERSION.SDK_INT), false)); if (android.os.Build.VERSION.SDK_INT >= 23) { li.add(new FingerprintItem("VERSION", "BASE_OS", Build.VERSION.BASE_OS, Build.VERSION.BASE_OS, false)); li.add(new FingerprintItem("VERSION", "PREVIEW_SDK_INT", String.valueOf(Build.VERSION.PREVIEW_SDK_INT), String.valueOf(Build.VERSION.PREVIEW_SDK_INT), false)); li.add(new FingerprintItem("VERSION", "SECURITY_PATCH", Build.VERSION.SECURITY_PATCH, Build.VERSION.SECURITY_PATCH, false)); } li.add(new FingerprintItem("BUILD", "BOARD", Build.BOARD, Build.BOARD, false)); li.add(new FingerprintItem("BUILD", "BOOTLOADER", Build.BOOTLOADER, Build.BOOTLOADER, false)); li.add(new FingerprintItem("BUILD", "BRAND", Build.BRAND, Build.BRAND, false)); li.add(new FingerprintItem("BUILD", "CPU_ABI", Build.CPU_ABI, Build.CPU_ABI, false)); li.add(new FingerprintItem("BUILD", "CPU_ABI2", Build.CPU_ABI2, Build.CPU_ABI2, false)); li.add(new FingerprintItem("BUILD", "DEVICE", Build.DEVICE, Build.DEVICE, false)); li.add(new FingerprintItem("BUILD", "DISPLAY", Build.DISPLAY, Build.DISPLAY, false)); li.add(new FingerprintItem("BUILD", "FINGERPRINT", Build.FINGERPRINT, Build.FINGERPRINT, false)); li.add(new FingerprintItem("BUILD", "HARDWARE", Build.HARDWARE, Build.HARDWARE, false)); li.add(new FingerprintItem("BUILD", "HOST", Build.HOST, Build.HOST, false)); li.add(new FingerprintItem("BUILD", "ID", Build.ID, Build.ID, false)); li.add(new FingerprintItem("BUILD", "MANUFACTURER", Build.MANUFACTURER, Build.MANUFACTURER, false)); li.add(new FingerprintItem("BUILD", "MODEL", Build.MODEL, Build.MODEL, false)); li.add(new FingerprintItem("BUILD", "PRODUCT", Build.PRODUCT, Build.PRODUCT, false)); li.add(new FingerprintItem("BUILD", "RADIO", Build.RADIO, Build.RADIO, false)); li.add(new FingerprintItem("BUILD", "SERIAL", Build.SERIAL, Build.SERIAL, false)); li.add(new FingerprintItem("BUILD", "TAGS", Build.TAGS, Build.TAGS, false)); li.add(new FingerprintItem("BUILD", "TYPE", Build.TYPE, Build.TYPE, false)); li.add(new FingerprintItem("BUILD", "USER", Build.USER, Build.USER, false)); list.fingerprintItems = li; Gson gson = new GsonBuilder().create(); SharedPreferences.Editor editor = mPrefs.edit(); String json = gson.toJson(list); editor.putString(Config.SP_FINGERPRINT_HOOKS, json); editor.apply(); }
Example 17
Source File: WifiStateChangeService.java From fdroidclient with GNU General Public License v3.0 | 4 votes |
private void setSsid(WifiInfo wifiInfo) { if (wifiInfo != null && wifiInfo.getBSSID() != null) { String ssid = wifiInfo.getSSID(); Utils.debugLog(TAG, "Have wifi info, connected to " + ssid); if (ssid == null) { FDroidApp.ssid = getString(R.string.swap_blank_wifi_ssid); } else { FDroidApp.ssid = ssid.replaceAll("^\"(.*)\"$", "$1"); } FDroidApp.bssid = wifiInfo.getBSSID(); } else { WifiApControl wifiApControl = null; try { wifiApControl = WifiApControl.getInstance(this); wifiApControl.isEnabled(); } catch (NullPointerException e) { wifiApControl = null; } Utils.debugLog(TAG, "WifiApControl: " + wifiApControl); if (wifiApControl == null && FDroidApp.ipAddressString != null) { wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null && wifiInfo.getBSSID() != null) { setSsid(wifiInfo); } else { FDroidApp.ssid = getString(R.string.swap_active_hotspot, ""); } } else if (wifiApControl != null && wifiApControl.isEnabled()) { WifiConfiguration wifiConfiguration = wifiApControl.getConfiguration(); Utils.debugLog(TAG, "WifiConfiguration: " + wifiConfiguration); if (wifiConfiguration == null) { FDroidApp.ssid = getString(R.string.swap_active_hotspot, ""); FDroidApp.bssid = ""; return; } if (wifiConfiguration.hiddenSSID) { FDroidApp.ssid = getString(R.string.swap_hidden_wifi_ssid); } else { FDroidApp.ssid = wifiConfiguration.SSID; } FDroidApp.bssid = wifiConfiguration.BSSID; } } }
Example 18
Source File: WifiWizard2.java From WifiWizard2 with Apache License 2.0 | 4 votes |
/** * This method retrieves the WifiInformation for the (SSID or BSSID) currently connected network. * * @param callbackContext A Cordova callback context * @param basicIdentifier A flag to get BSSID if true or SSID if false. * @return true if SSID found, false if not. */ private boolean getWifiServiceInfo(CallbackContext callbackContext, boolean basicIdentifier) { if (API_VERSION >= 23 && !cordova.hasPermission(ACCESS_FINE_LOCATION)) { //Android 9 (Pie) or newer requestLocationPermission(WIFI_SERVICE_INFO_CODE); bssidRequested = basicIdentifier; return true; } else { WifiInfo info = wifiManager.getConnectionInfo(); if (info == null) { callbackContext.error("UNABLE_TO_READ_WIFI_INFO"); return false; } // Only return SSID or BSSID when actually connected to a network SupplicantState state = info.getSupplicantState(); if (!state.equals(SupplicantState.COMPLETED)) { callbackContext.error("CONNECTION_NOT_COMPLETED"); return false; } String serviceInfo; if (basicIdentifier) { serviceInfo = info.getBSSID(); } else { serviceInfo = info.getSSID(); } if (serviceInfo == null || serviceInfo.isEmpty() || serviceInfo == "0x") { callbackContext.error("WIFI_INFORMATION_EMPTY"); return false; } // http://developer.android.com/reference/android/net/wifi/WifiInfo.html#getSSID() if (serviceInfo.startsWith("\"") && serviceInfo.endsWith("\"")) { serviceInfo = serviceInfo.substring(1, serviceInfo.length() - 1); } callbackContext.success(serviceInfo); return true; } }
Example 19
Source File: WifiWizard2.java From WifiWizard2 with Apache License 2.0 | 3 votes |
@Override public void onReceive(final Context context, final Intent intent) { if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) { Log.d(TAG, "NETWORK_STATE_CHANGED_ACTION"); NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); WifiInfo info = WifiWizard2.this.wifiManager.getConnectionInfo(); // Checks that you're connected to the desired network if (networkInfo.isConnected() && info.getNetworkId() > -1) { final String ssid = info.getSSID().replaceAll("\"", ""); final String bssid = info.getBSSID(); Log.d(TAG, "Connected to '" + ssid + "' @ " + bssid); // Verify the desired network ID is what we actually connected to if ( desired != null && info.getNetworkId() == desired.apId ) { onSuccessfulConnection(); } } } }
Example 20
Source File: WifiUtils.java From DevUtils with Apache License 2.0 | 2 votes |
/** * 获取连接的 BSSID * @param wifiInfo {@link WifiInfo} * @return BSSID */ public static String getBSSID(final WifiInfo wifiInfo) { if (wifiInfo == null) return null; return wifiInfo.getBSSID(); }