'Is there anyway to mimic turn airplane mode on and off? (BluetoothLeScanner sometimes not detecting any signals)

Came across a problem that sometimes BluetoothLeScanner can't detect anything for about 10 or 20 seconds.

(this problem can be reproduced by running the below code multiple times, scanner will not work for a while)

bluetoothAdapter.getBluetoothLeScanner().stopScan(mScanCallback);
bluetoothAdapter.getBluetoothLeScanner().startScan(mScanCallback);

I tried to restart BluetoothLeScanner programmatically and manually turn on and off wifi + Bluetooth but it did not work, always need to wait 10 sec or so until the system detect the BLE signals.

I ended up turning airplane mode on and off, and everything works perfectly (works every time), I don't need to wait, just turn it on and off, and the system will detect the BLE signal.

What I'm trying to do is, make a button, when I click on it, the app will turn airplane mode on and off, but this seems not doable for Android 4.2 later version. Is there any way I can reproduce a similar function that works like airplane mode? (maybe be clear some cache?)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source