android.net.wifi.ScanResult Java Examples
The following examples show how to use
android.net.wifi.ScanResult.
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: WifiManagerModule.java From react-native-wifi-manager with MIT License | 6 votes |
@ReactMethod public void list(Callback successCallback, Callback errorCallback) { try { WifiManager mWifiManager = (WifiManager) getReactApplicationContext().getSystemService(Context.WIFI_SERVICE); List < ScanResult > results = mWifiManager.getScanResults(); WritableArray wifiArray = Arguments.createArray(); for (ScanResult result: results) { if(!result.SSID.equals("")){ wifiArray.pushString(result.SSID); } } successCallback.invoke(wifiArray); } catch (IllegalViewOperationException e) { errorCallback.invoke(e.getMessage()); } }
Example #2
Source File: WiFiNetwork.java From upcKeygen with GNU General Public License v2.0 | 6 votes |
private WiFiNetwork(Parcel in) { ssidName = in.readString(); if (in.readInt() == 1) macAddress = in.readString(); else macAddress = ""; if (in.readInt() == 1) encryption = in.readString(); else encryption = OPEN; level = in.readInt(); mode = in.readInt(); keygens = new ArrayList<>(); in.readList(keygens, Keygen.class.getClassLoader()); if (in.readInt() == 1) scanResult = in.readParcelable(ScanResult.class.getClassLoader()); else scanResult = null; }
Example #3
Source File: GosChooseDeviceActivity.java From Gizwits-SmartBuld_Android with MIT License | 6 votes |
private void initData() { list = new ArrayList<ScanResult>(); list = (ArrayList<ScanResult>) NetUtils.getCurrentWifiScanResult(GosChooseDeviceActivity.this); softList = new ArrayList<ScanResult>(); ScanResult scanResult; for (int i = 0; i < list.size(); i++) { scanResult = list.get(i); if (scanResult.SSID.length() > SoftAP_Start.length()) { if (scanResult.SSID.contains(SoftAP_Start)) { softList.add(scanResult); } } } myadapter = new Myadapter(softList); listView.setAdapter(myadapter); }
Example #4
Source File: ConnectorUtils.java From WifiUtils with Apache License 2.0 | 6 votes |
public static boolean reEnableNetworkIfPossible(@Nullable final WifiManager wifiManager, @Nullable final ScanResult scanResult) { if (wifiManager == null) { return false; } @Nullable final List<WifiConfiguration> configurations = wifiManager.getConfiguredNetworks(); if (configurations == null || scanResult == null || configurations.isEmpty()) { return false; } boolean result = false; for (WifiConfiguration wifiConfig : configurations) if (Objects.equals(scanResult.BSSID, wifiConfig.BSSID) && Objects.equals(scanResult.SSID, trimQuotes(wifiConfig.SSID))) { result = wifiManager.enableNetwork(wifiConfig.networkId, true); break; } wifiLog("reEnableNetworkIfPossible " + result); return result; }
Example #5
Source File: ConnectorUtils.java From WifiUtils with Apache License 2.0 | 6 votes |
@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE}) static boolean cleanPreviousConfiguration(@Nullable final WifiManager wifiManager, @NonNull final ScanResult scanResult) { if (wifiManager == null) { return false; } //On Android 6.0 (API level 23) and above if my app did not create the configuration in the first place, it can not remove it either. final WifiConfiguration config = ConfigSecurities.getWifiConfiguration(wifiManager, scanResult); wifiLog("Attempting to remove previous network config..."); if (config == null) { return true; } if (wifiManager.removeNetwork(config.networkId)) { wifiManager.saveConfiguration(); return true; } return false; }
Example #6
Source File: WifiHelper.java From BaseProject with MIT License | 6 votes |
/** * 连接加密wifi */ @RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE) public boolean connection( @NonNull ScanResult scanResult, @NonNull String password) { WifiConfiguration wifiConfiguration = new WifiConfiguration(); wifiConfiguration.SSID = "\"" + scanResult.SSID + "\""; wifiConfiguration.preSharedKey = "\"" + password + "\""; wifiConfiguration.hiddenSSID = true; wifiConfiguration.status = WifiConfiguration.Status.ENABLED; wifiConfiguration.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); wifiConfiguration.allowedKeyManagement.set(getEncryptionType(scanResult)); wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA); return connection(wifiConfiguration); }
Example #7
Source File: MainActivity.java From connectivity-samples with Apache License 2.0 | 6 votes |
private List<ScanResult> find80211mcSupportedAccessPoints( @NonNull List<ScanResult> originalList) { List<ScanResult> newList = new ArrayList<>(); for (ScanResult scanResult : originalList) { if (scanResult.is80211mcResponder()) { newList.add(scanResult); } if (newList.size() >= RangingRequest.getMaxPeers()) { break; } } return newList; }
Example #8
Source File: GosMessageHandler.java From Gizwits-SmartBuld_Android with MIT License | 6 votes |
public void run() { if (mcContext == null) { return; } newDeviceList.clear(); List<ScanResult> currentWifiScanResult = NetUtils.getCurrentWifiScanResult(mcContext); int flog = 0; for (ScanResult scanResult : currentWifiScanResult) { String ssid = scanResult.SSID; // 获取系统的NotificationManager服务 nm = (NotificationManager) mcContext.getSystemService(Context.NOTIFICATION_SERVICE); if (ssid.contains(GosBaseActivity.SoftAP_Start) && ssid.length() > GosBaseActivity.SoftAP_Start.length() && !newDeviceList.toString().contains(ssid)) { newDeviceList.add(ssid); flog++; send(ssid, flog); } } if (mainHandler != null && newDeviceList.size() > 0) { mainHandler.sendEmptyMessage(SHOWDIALOG); } looper.postDelayed(mRunnable, 2000); }
Example #9
Source File: WifiHelper.java From AndroidBasicProject with MIT License | 6 votes |
/** * 连接加密wifi * @param scanResult * @param password * @return */ @RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE) public boolean connection(ScanResult scanResult, String password) { WifiConfiguration wifiConfiguration = new WifiConfiguration(); wifiConfiguration.SSID = "\"" + scanResult.SSID + "\""; wifiConfiguration.preSharedKey = "\"" + password + "\""; wifiConfiguration.hiddenSSID = true; wifiConfiguration.status = WifiConfiguration.Status.ENABLED; wifiConfiguration.allowedAuthAlgorithms.set( WifiConfiguration.AuthAlgorithm.OPEN); wifiConfiguration.allowedGroupCiphers.set( WifiConfiguration.GroupCipher.TKIP); wifiConfiguration.allowedGroupCiphers.set( WifiConfiguration.GroupCipher.CCMP); wifiConfiguration.allowedKeyManagement.set( getEncryptionType(scanResult)); wifiConfiguration.allowedPairwiseCiphers.set( WifiConfiguration.PairwiseCipher.TKIP); wifiConfiguration.allowedPairwiseCiphers.set( WifiConfiguration.PairwiseCipher.CCMP); wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA); return connection(wifiConfiguration); }
Example #10
Source File: WifiHelper.java From BaseProject with MIT License | 6 votes |
/** * 扫描WiFi列表 */ @RequiresPermission(allOf = {Manifest.permission.CHANGE_WIFI_STATE, Manifest.permission.ACCESS_WIFI_STATE}) public List<ScanResult> getScanResults() { List<ScanResult> list = null; //开始扫描WiFi boolean f = mWifiManager.startScan(); if (!f) { getScanResults(); } else { // 得到扫描结果 list = mWifiManager.getScanResults(); } return list; }
Example #11
Source File: CacheTest.java From WiFiAnalyzer with GNU General Public License v3.0 | 6 votes |
@Test public void testAddCompliesToMaxCacheSize() { // setup int cacheSize = 2; when(configuration.isSizeAvailable()).thenReturn(false); List<List<ScanResult>> expected = new ArrayList<>(); // execute for (int i = 0; i < cacheSize; i++) { List<ScanResult> scanResults = Collections.emptyList(); expected.add(scanResults); fixture.add(scanResults, wifiInfo); } // validate assertEquals(cacheSize, expected.size()); assertEquals(expected.get(cacheSize - 1), fixture.getFirst()); assertEquals(expected.get(cacheSize - 2), fixture.getLast()); }
Example #12
Source File: WifiWrapper.java From gsn with GNU General Public License v3.0 | 6 votes |
@SuppressLint("UseValueOf") public void onReceive(Context c, Intent intent) { List<ScanResult> wifiScanList = mainWifiObj.getScanResults(); Log.d("wifi-scanning", "received " + wifiScanList.size()); StreamElement streamElement = null; if (wifiScanList.size() == 0){ streamElement = new StreamElement(w.getFieldList(), w.getFieldType(), new Serializable[] { 0.0, mainWifiObj.isWifiEnabled()?1.0:0.0 , 0.0 }); ((WifiWrapper) w).postStreamElement(streamElement); } for(int i = 0; i < wifiScanList.size(); i++){ streamElement = new StreamElement(w.getFieldList(), w.getFieldType(), new Serializable[] { converTingBSSID(wifiScanList.get(i).BSSID.substring(0, 8)), converTingBSSID(wifiScanList.get(i).BSSID.substring(8)), wifiScanList.get(i).level }); ((WifiWrapper) w).postStreamElement(streamElement); storage.updateWifiFrequency(wifiScanList.get(i).BSSID); } // unregisterReceiver(wifiReciever); // registerReceiver(wifiReciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); scanning = false; }
Example #13
Source File: AppNetworkMgr.java From AndroidWallet with GNU General Public License v3.0 | 6 votes |
/** * 过滤扫描结果 * * @param context * @param bssid * @return */ public static ScanResult getScanResultsByBSSID(Context context, String bssid) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); ScanResult scanResult = null; boolean f = wifiManager.startScan(); if (!f) { getScanResultsByBSSID(context, bssid); } List<ScanResult> list = wifiManager.getScanResults(); if (list != null) { for (int i = 0; i < list.size(); i++) { scanResult = list.get(i); if (scanResult.BSSID.equals(bssid)) { break; } } } return scanResult; }
Example #14
Source File: WifiInfo.java From MobileInfo with Apache License 2.0 | 6 votes |
private static void scanSuccess(WifiManager wifiManager, WifiBean wifiBean, long startTime, WifiScanListener wifiScanListener) { List<ScanResult> results = wifiManager.getScanResults(); wifiBean.setWifiScanStatus(results.size() != 0); JSONArray scanArray = new JSONArray(); for (ScanResult scanResult : results) { WifiBean.WifiResultBean wifiResultBean = new WifiBean.WifiResultBean(); wifiResultBean.setBSSID(scanResult.BSSID); wifiResultBean.setSSID(scanResult.SSID); wifiResultBean.setCapabilities(scanResult.capabilities); wifiResultBean.setLevel(scanResult.level); scanArray.put(wifiResultBean.toJSONObject()); } wifiBean.setWifiScanResult(scanArray); wifiBean.setTime(System.currentTimeMillis() - startTime); wifiScanListener.onResult(wifiBean.toJSONObject()); }
Example #15
Source File: WifiVo.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 扫描 Wifi 信息 * @param listWifiVos 数据源 * @param listScanResults 扫描返回的数据 * @return {@code true} success, {@code false} fail */ public static boolean scanWifiVos(final List<WifiVo> listWifiVos, final List<ScanResult> listScanResults) { if (listWifiVos == null || listScanResults == null) return false; // 清空旧数据 listWifiVos.clear(); // 遍历 Wifi 列表数据 for (int i = 0, len = listScanResults.size(); i < len; i++) { // 如果出现异常、或者失败, 则无视当前的索引 Wifi 信息 try { // 获取当前索引的 Wifi 信息 ScanResult scanResult = listScanResults.get(i); // 防止 Wifi 名长度为 0 if (scanResult.SSID.length() == 0) { continue; } // 保存 Wifi 信息 listWifiVos.add(createWifiVo(scanResult)); } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "scanWifiVos"); } } return true; }
Example #16
Source File: ConnectorUtils.java From WifiUtils with Apache License 2.0 | 5 votes |
@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE}) static boolean connectToWifi(@NonNull final Context context, @Nullable final WifiManager wifiManager, @NonNull final ScanResult scanResult, @NonNull final String password) { if (wifiManager == null) { return false; } if (isAndroidQOrLater()) { final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return connectAndroidQ(connectivityManager, scanResult, password); } return connectPreAndroidQ(context, wifiManager, scanResult, password); }
Example #17
Source File: MyAdapter.java From RairDemo with Apache License 2.0 | 5 votes |
public MyAdapter(Context context, List<ScanResult> datas, WifiManager wifiManager) { this.mContext = context; inflater = LayoutInflater.from(mContext); this.datas = datas; this.wifiManager = wifiManager; wiFiUtil = WiFiUtil.getInstance(context); }
Example #18
Source File: NetUtil.java From ESeal with Apache License 2.0 | 5 votes |
/** * 获取所有搜索的WiFi的SSID */ public static List<String> getScanWifiSSIDList(Activity activity) { WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE); List<String> result = new ArrayList<>(); for (ScanResult scanResult : wifiManager.getScanResults()) { result.add(scanResult.SSID); } return result; }
Example #19
Source File: MainActivity.java From NetworkEvents with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") @Subscribe public void onEvent(WifiSignalStrengthChanged event) { List<String> wifiScanResults = new ArrayList<>(); for (ScanResult scanResult : event.getWifiScanResults()) { wifiScanResults.add(scanResult.SSID); } int itemLayoutId = android.R.layout.simple_list_item_1; accessPoints.setAdapter(new ArrayAdapter<>(this, itemLayoutId, wifiScanResults)); String message = getString(R.string.wifi_signal_strength_changed); Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); }
Example #20
Source File: WifiIntentReceiver.java From find-client-android with MIT License | 5 votes |
/** * Returns true if the given scan should be logged, or false if it is an * ad-hoc AP or if it is an AP that has opted out of Google's collection * practices. */ private static boolean shouldLog(final ScanResult sr) { // Only apply this test if we have exactly 17 character long BSSID which should // be the case. final char secondNybble = sr.BSSID.length() == 17 ? sr.BSSID.charAt(1) : ' '; if(AD_HOC_HEX_VALUES.contains(secondNybble)) { return false; } else { return true; } }
Example #21
Source File: WifiAutoConnectManager.java From YiZhi with Apache License 2.0 | 5 votes |
public static WifiCipherType getCipherType(Context context, String ssid) { WifiManager wifiManager = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); List<ScanResult> list = wifiManager.getScanResults(); for (ScanResult scResult : list) { if (!StringUtils.isEmpty(scResult.SSID) && scResult.SSID.equals(ssid)) { String capabilities = scResult.capabilities; if (!StringUtils.isEmpty(capabilities)) { if (capabilities.contains("WPA") || capabilities.contains("wpa")) { LogUtils.i("wpa"); return WifiCipherType.WIFICIPHER_WPA; } else if (capabilities.contains("WEP") || capabilities.contains("wep")) { LogUtils.i("wep"); return WifiCipherType.WIFICIPHER_WEP; } else { LogUtils.i("no"); return WifiCipherType.WIFICIPHER_NOPASS; } } } } return WifiCipherType.WIFICIPHER_INVALID; }
Example #22
Source File: WifiScanner.java From Rumble with GNU General Public License v3.0 | 5 votes |
@Override public HashSet<LinkLayerNeighbour> getNeighbourList() { HashSet<LinkLayerNeighbour> ret = new HashSet<>(); for(Map.Entry<String, ScanResult> entry : accessPoints.entrySet()) { ret.add(new WifiAPNeighbour(entry.getValue())); } return ret; }
Example #23
Source File: CacheTest.java From WiFiAnalyzer with GNU General Public License v3.0 | 5 votes |
@Test public void testAddWithSizeAvailable() { // setup List<ScanResult> scanResults = Collections.emptyList(); // execute fixture.add(scanResults, wifiInfo); // validate assertEquals(scanResults, fixture.getFirst()); }
Example #24
Source File: ConnectorUtils.java From WifiUtils with Apache License 2.0 | 5 votes |
@Nullable static ScanResult matchScanResult(@NonNull String ssid, @NonNull String bssid, @NonNull Iterable<ScanResult> results) { for (ScanResult result : results) { if (Objects.equals(result.SSID, ssid) && Objects.equals(result.BSSID, bssid)) { return result; } } return null; }
Example #25
Source File: ConnectorUtils.java From WifiUtils with Apache License 2.0 | 5 votes |
@Nullable static ScanResult matchScanResultBssid(@NonNull String bssid, @NonNull Iterable<ScanResult> results) { for (ScanResult result : results) { if (Objects.equals(result.BSSID, bssid)) { return result; } } return null; }
Example #26
Source File: GosMessageHandler.java From gokit-android with MIT License | 5 votes |
public void run() { if (mcContext == null) { return; } newDeviceList.clear(); List<ScanResult> currentWifiScanResult = NetUtils .getCurrentWifiScanResult(mcContext); int flog = 0; if (currentWifiScanResult != null) { for (ScanResult scanResult : currentWifiScanResult) { String ssid = scanResult.SSID; // 获取系统的NotificationManager服务 nm = (NotificationManager) mcContext .getSystemService(Context.NOTIFICATION_SERVICE); if (ssid.contains(GosBaseActivity.SoftAP_Start) && ssid.length() > GosBaseActivity.SoftAP_Start .length() && !newDeviceList.toString().contains(ssid)) { newDeviceList.add(ssid); flog++; send(ssid, flog); } } } if (mainHandler != null && newDeviceList.size() > 0) { mainHandler.sendEmptyMessage(SHOWDIALOG); } looper.postDelayed(mRunnable, 2000); }
Example #27
Source File: MainActivity.java From connectivity-samples with Apache License 2.0 | 5 votes |
@Override public void onScanResultItemClick(ScanResult scanResult) { Log.d(TAG, "onScanResultItemClick(): ssid: " + scanResult.SSID); Intent intent = new Intent(this, AccessPointRangingResultsActivity.class); intent.putExtra(SCAN_RESULT_EXTRA, scanResult); startActivity(intent); }
Example #28
Source File: WifiHooker.java From DoraemonKit with Apache License 2.0 | 5 votes |
@Override public Object onInvoke(Object originService, Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException { if (!GpsMockManager.getInstance().isMocking()) { return method.invoke(originService, args); } return new ArrayList<ScanResult>(); }
Example #29
Source File: ConfigSecurities.java From WifiUtils with Apache License 2.0 | 5 votes |
/** * @return The security of a given {@link ScanResult}. */ public static String getSecurityPrettyPlusWps(@Nullable ScanResult scanResult) { if (scanResult == null) { return ""; } String result = getSecurity(scanResult); if (scanResult.capabilities.contains("WPS")) { result = result + ", WPS"; } return result; }
Example #30
Source File: WifiAp.java From PrivacyStreams with Apache License 2.0 | 5 votes |
WifiAp(ScanResult scanResult, boolean connected) { this.setFieldValue(TIMESTAMP, scanResult.timestamp); this.setFieldValue(BSSID, scanResult.BSSID); this.setFieldValue(SSID, scanResult.SSID); this.setFieldValue(FREQUENCY, scanResult.frequency); this.setFieldValue(RSSI, scanResult.level); this.setFieldValue(CONNECTED, connected); }