startScan() in WifiManager deprecated in Android P

不羁的心 提交于 2019-12-17 17:56:19

问题


How to get scan result from wifi for example every 3 seconds, without mWifimanager.startScan();

Google says :

startScan() This method was deprecated in API level P. The ability for apps to trigger scan requests will be removed in a future release.

Notice for this API level i'm using List<ScanResult> results = mWifiManager.getScanResults(); without calling startScan , the list contains the wifi AP's but it makes updated very very slow

Update to 12 January 2019 : https://issuetracker.google.com/issues/112688545


回答1:


Google has now documented the limitations for startScan() function in Android P:

"We are further limiting the number of scans apps can request to improve network performance and improve battery life.

The WifiManager.startScan() usage is limited to: - Each foreground app is restricted to 4 scans every 2 minutes. - All background apps combined are restricted to one scan every 30 minutes."

Source: https://issuetracker.google.com/issues/79906367

Edit 8-Aug-2018: Information has been added also here: https://developer.android.com/guide/topics/connectivity/wifi-scan




回答2:


I think in API level P they're planning to move startScan() to a different class (WifiScanner) all together with some key differences.

See: https://android.googlesource.com/platform/frameworks/base/+/android-p-preview-1/wifi/java/android/net/wifi/WifiScanner.java

If there's an alternative solution to this, I'd love to hear it as well.

For now, I might just use startScan() until official docs are released.




回答3:


startScan() is actually pretty buggy on P, as I raised Google Issue 79906367.

I don't think that WifiScanner is the replacement either, as that is marked as a SystemApi which means no access for Apps...

Hopefully we will hear soon, as RTT still means you need to scan for APs which support 802.11mc using ScanResult is80211mcResponder which you check before performing RTT Ranging on the AP.




回答4:


StartScan() method is deprecated in Android P and new RTT protocol from 802.11mc standard has to be used with trilateration Algorithms. https://android-developers.googleblog.com/2018/03/previewing-android-p.html

X,Y position of the AP should to be knonw for accurate positioning and the AP should support 802.11mc's Fine Time Measurement. Intel® Wireless-AC 9260 support 802.11mc and several APs start supporting 802.11mc standard.

A couple of examples:

  • https://medium.com/@rafaelmiguel.ortega/android-p-first-taste-of-rtt-support-febefb679775
  • https://medium.com/@plinzen/perform-wifi-round-trip-time-measurements-with-android-p-9ffc5277ac6a



回答5:


I think google is planning to restrict application from scanning wifi.

This method was deprecated in API level 28. The ability for apps to trigger scan requests will be removed in a future release. Check the documentation here.




回答6:


From WifiManager#EXTRA_RESULTS_UPDATED

Note: Apps holding android.Manifest.permission.NETWORK_SETTINGS permission are exempted from scan throttling.

Note: This is a system permission, regular apps can't use it without rooting and moving the app to the 'privileged' location or having it baked into a custom ROM.




回答7:


It appears Googles intention might be to force developers to use WifiRttManager instead for indoor location atleast [1]. Or rely on usual Google Play location services, which is an option in some use cases, but definitely not all. It's optimised for the average use case. No use case is the average use case.

Unfortunately with the way WifiRttManager calculates location it requires the wifi accesspoints to have 802.11mc. However you don't need to connect to these points. Virtually 0 routers today have this standard. [2] [3] [4] With 3 access points you can get location close to 1-2m accuracy.

Who knows if they'll place restrictions on this functionality as well though. There is simply no excuse for taking this choice away from users and developers. Disgusting.

So it appears there will atleast be a dark age for indoor location. Perhaps a workaround is to have devices you are connected to and ping them.

[1] https://developer.android.com/reference/android/net/wifi/rtt/WifiRttManager

[2] https://github.com/Plinzen/android-rttmanager-sample

Additional reading

[3] https://en.wikipedia.org/wiki/IEEE_802.11mc

[4] https://fit-iot.com/web/wifi-indoor-positioning/



来源:https://stackoverflow.com/questions/49178307/startscan-in-wifimanager-deprecated-in-android-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!