0

From the Android document we know that WiFiManager.startScan() invoke a passive WiFi scan. It usually takes more time than an active scan. As a result, I would like to invoke an active scan using the method below.

In the previous WiFiManager.java there is a hidden method called startScanActive. We cannot call it directly, but we can invoke it via java reflection. What does @hide mean in the Android source code?

However, this method disappeared in the Android 4.3+. Then, how to begin an active WiFi scan in Android 4.3+?

Thank you

Community
  • 1
  • 1
jack
  • 125
  • 1
  • 9

2 Answers2

0

AFAIK, Active Scan is not possible and so is removed from the later API levels.

It is a device and/or OS version dependent setting. On the Nexus One for example it takes roughly a second to scan whereas on the G1 it takes significantly longer (or get fresh results after a few scans).

Moreover, Android does passive scans, it listens for beacons. Doing an active scan can create a lot of congestion on the network by sending out probe requests and waiting for probe responses.

Refer: android-wifi-active-scans and WifiManager.

Community
  • 1
  • 1
sjain
  • 23,126
  • 28
  • 107
  • 185
  • Are you sure Android does passive scans? My HTC One M8 sends Probe Requests periodically, even when WiFi is turned off (but "scanning always available" option is enabled). – Alexandr Zarubkin Sep 24 '15 at 09:22
-1

Then you can use the following in your activity class:

WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); wifiManager.setWifiEnabled(false);

Guru
  • 186
  • 14