I am trying to scan wifi networks every 2 minutes. I am using service for that. When the phone is "active" or "in use" after startscan()
called I get SCAN_RESULTS_AVAILABLE_ACTION
in 6 sec. So i can scan for wifis periodically. But after the phone has not been touched by anyone for a certain time (10 min) startscan() stops "working" and only after 10 min getting result. Anybody experienced this?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
According to this I have found the solution - this is because the Wifi sleep policy. You can set your wifi device never goes to sleep with this:
Be sure, that you added this permission in
AndroidManifest.xml
file:the scanning period will be 5-15s - and this is automatic - you dont need to call
startscan()
. more info about Android scanning process can be found here.Edit:
maybe this is even better solution if you only want to scan for hotspots:
WIFI_MODE_SCAN_ONLY
- it can be activated by:dont forget to release it, more info about
WifiLock
herealso define this permission:
Edit2 this works as well:
you can enable, and disable wifi periodically:
then scan after your broadcastreceiver gets the action containing
WIFI_STATE_ENABLED
extra