I have an application to scan beacons. I don't face any problems in Lollipop and Oreo however, in Marshmellow and Nougat, no beacons are detected after some time (roughly 90 minutes). I read online that Nougat stops scanning after 30 minutes and hence I stop/start scan once every 5 minutes. Things I observed -
1) All devices are tested at the same time and hence I am sure there's no problem with beacon transmission.
2) I observe continuous scanning when the wifi is off.
3) Once it stops scanning, the device doesn't display any nearby bluetooth devices on Settings tab (maybe the bluetooth is broken?)
4) Battery historian shows ble_scanning to be on all the time
5) Restarting bluetooth solves the problem and starts scanning. I don't want to introduce turning off/on bluetooth everytime within the app.
I came across this post https://github.com/AltBeacon/android-beacon-library/issues/289 but the post is for Lollipop where I am not facing a problem. It talks about setting beaconManager.setAndroidLScanningDisabled(true). Currently, I am not using the library. Is there any way I can solve this issue? I am using XCody Y19 device Android 7.0
Unless you have reproduced this problem on several device models from different manufacturers with Android 6.x and 7.x, I think it is more likely that this problem is device-specific. It may be introduced by the bluetooth chip, or the device-specific firmware in the ROM that bridges the bluetooth hardware to the Android bluetooth stack.
While this is merely conjecture based on limited data samples in your question, I have seen similar issues on Huawei, Samsung J3, Moto E3 and Moto G5 devices running Android 6.x and 7.x. But I have not seen such issues on Nexus devices running Android 6.x and 7.x. For this reason, I think similar issues may not be OS-specific.
While it is not ideal, cycling power to bluetooth is one of the few levers of control that Android apps have over the bluetooth stack. It can sometimes (but not always) clear low-level bluetooth stack problems for which no other APIs exist. For this reason, an optional BluetoothMedic was added to the Android Beacon Library that looks for bluetooth stack crashes and (optionally) cycles power to bluetooth when such problems are found. This allows you to ignore such problems and focus on your application logic.
While I understand you are not using the library, if you are interested you may copy the source code for the BluetoothMedic class from the pull request here: https://github.com/AltBeacon/android-beacon-library/pull/644