.scan() not working on Android 9
See original GitHub issue<!–
Have you read the plugins’ Code of Conduct? By creating an Issue, you are expected to comply with it, including treating everyone with respect: https://github.com/tripflex/wifiwizard2/blob/master/CODE_OF_CONDUCT.md
–>
Possibly related to #44
Prerequisites
Check all boxes if you have done the following:
- Checked that your issue isn’t already filed: https://github.com/tripflex/wifiwizard2/issues
- Make sure you fill out the Issue Type below
Issue type
Select all that apply
- Bug
- Enhancement
- Task
- Question
- Other
Description
Have been using WifiWizard previously, and now WifiWizard2 (version 3.1.0) in an Ionic app publishing to Android. We’re really only using it for the .scan() and .getConnectedSSID() methods. Both work well on Android 8.1 and below. But on our tests on Android 9 (via the Google Pixel 2 XL), they always fail via timeout. Here are the logs for one attempt at .scan():
09-06 11:18:36.995 6301-6423/com.x.y.z D/WifiWizard2: WifiWizard2: verifyWifiEnabled entered.
09-06 11:18:36.995 6301-6423/com.x.y.z V/WifiWizard2: Entering startScan
09-06 11:18:36.997 6301-6423/com.x.y.z V/WifiWizard2: Submitting timeout to threadpool
09-06 11:18:36.998 6301-6423/com.x.y.z V/WifiWizard2: Registering broadcastReceiver
09-06 11:18:36.998 6301-6424/com.x.y.z V/WifiWizard2: Entering timeout
09-06 11:18:36.999 6301-6423/com.x.y.z V/WifiWizard2: Scan failed
09-06 11:18:47.000 6301-6424/com.x.y.z V/WifiWizard2: Thread sleep done
09-06 11:18:47.005 6301-6424/com.x.y.z V/WifiWizard2: In timeout, error
The thing that sticks out to me is that “Scan failed” gets logged .005 seconds after the request starts. That would seem to be triggered by these lines in the plugin (326-330):
if (!wifiManager.startScan()) {
Log.v(TAG, "Scan failed");
callbackContext.error("SCAN_FAILED");
return false;
}
Android 9 has deprecated this method in WifiManager, it’s true, and introduced some new wifi scanning throttling, detailed here: https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-restrictions
However I don’t think it’s been removed entirely. And I’m not getting throttling behavior, I’m getting immediate failure, as if that method doesn’t even exist.
Any thoughts or assistance appreciated. I’ll keep working on it.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
@jameskane05 If you want to use the scan on later android devices, you have to enable GPS unfortunately. Try that to see if that fixes your problem. I believe this was a bad Google decision.
This issue still exists in Android 9. The location is not enabled by default which leads to
SCAN_FAILED
error. If manually enabled the GPS then it works.