Android 6 : start scan is blocked in background

Hi, I’m developing an app for Android that use Nearable Stickers. I’m trying to use a background service for scanning the stickers with NearableListener. The service works fine with my phone HTC ONE M7 (Lollipop) and the Motorola MotoG (Lollipop), but when I test it with Xiaomi redmi note 4 (android 6) there is a problem. If the service is running and the app is opened it works normally, but if I close or exit from the app after a few second the bluetooth scan stalls:
I/BluetoothLeScanner: start scan is blocked
when this happens the stickers are no longer acquired. If I reopen the activity the scanning resumes.
I would greatly appreciate help. Thank you!

Sounds like something specific to the Xiaomi phone. Would you mind reporting this as a bug on our GitHub?

It would be helpful if you enabled debug logs: EstimoteSDK.enableDebugLogging(true), and attached the output to your report.

Thanks!

I enabled the logs, the output is as follows. Anyway I reported the bug also on GitHub, thanks!

There are the logs when the scan works:

D/ActivityThread: BDC-Calling onReceive: intent=Intent { flg=0x114 cmp=com.example.selima.beaconmonitoring/com.estimote.sdk.service.BeaconService$ScanAlarmBroadcastReceiver (has extras) }, receiver=com.estimote.sdk.service.BeaconService$ScanAlarmBroadcastReceiver@df2ce1a
D/ActivityThread: SVC-Calling onStartCommand: com.estimote.sdk.service.BeaconService@42aeba7, flags=0, startId=1
D/BluetoothAdapter: isEnabled
D/BluetoothAdapter: 90696806: getState(). Returning 12
D/BluetoothAdapter: getLeState() returning 12
D/BluetoothAdapter: STATE_ON
D/BluetoothAdapter: getLeState() returning 12
D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5
I/BluetoothLeScanner: startRegisteration: mLeScanClients={com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter$1@af4c303=android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper@d49dd4b}
D/EstimoteSDK: com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter.start:248 STARTED SCAN
D/ActivityThread: BDC-Calling onReceive: intent=Intent { flg=0x114 cmp=com.example.selima.beaconmonitoring/com.estimote.sdk.service.BeaconService$ScanAlarmBroadcastReceiver (has extras) }, receiver=com.estimote.sdk.service.BeaconService$ScanAlarmBroadcastReceiver@ce24328
D/ActivityThread: SVC-Calling onStartCommand: com.estimote.sdk.service.BeaconService@42aeba7, flags=0, startId=2
D/BluetoothAdapter: isEnabled
D/BluetoothAdapter: 90696806: getState(). Returning 12
D/BluetoothAdapter: 90696806: getState(). Returning 12
D/BluetoothAdapter: getLeState() returning 12
D/BluetoothAdapter: STATE_ON
I/BluetoothLeScanner: startRegisteration: mLeScanClients={com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter$1@af4c303=android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper@d49dd4b} ,callback=com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter$1@af4c303
D/EstimoteSDK: com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter.stop:278 STOPPED SCAN
D/DiscoveredNearables: Discovered nearables: [Nearable{identifier='d83b9c869a83330b', hardwareVersion='SB0', firmwareVersion='Unknown', bootloaderVersion='SB1.0.0', firmwareState=APP, temperature=21.375, rssi=-65, isMoving=false, xAcceleration=62.5, yAcceleration=78.125, zAcceleration=1031.25, orientation=HORIZONTAL_UPSIDE_DOWN, currentMotionStateDuration=300, lastMotionStateDuration=3, batteryLevel=MEDIUM, power=LEVEL_7, region=Region{identifier=nearable-d83b9c869a83330b, proximityUUID=d0d3fa86-ca76-45ec-9bd9-6af4d83b9c86, major=39555, minor=13067, secure=false}, type=Fridge, color=Lemon Tart}, Nearable{identifier='86fae3fdcb26fbd3', hardwareVersion='SB0', firmwareVersion='Unknown', bootloaderVersion='Unknown', firmwareState=APP, temperature=21.563, rssi=-76, isMoving=false, xAcceleration=46.875, yAcceleration=-46.875, zAcceleration=-1000.0, orientation=HORIZONTAL, currentMotionStateDuration=300, lastMotionStateDuration=4, batteryLevel=MEDIUM, power=LEVEL_6, region=Region{identifier=nearable-86fae3fdcb26fbd3, proximityUUID=d0d3fa86-ca76-45ec-9bd9-6af486fae3fd, major=52006, minor=64467, secure=false}, type=Bed, color=Mint Cocktail}]
D/BluetoothAdapter: getLeState() returning 12
D/ISMOVE: 0 0false
D/TIME: 18:10:38

After exit from app the logs are:

D/BluetoothAdapter: isEnabled
D/BluetoothAdapter: 90696806: getState(). Returning 12
D/BluetoothAdapter: getLeState() returning 12
D/BluetoothAdapter: STATE_ON
D/BluetoothAdapter: getLeState() returning 12
D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=5
I/BluetoothLeScanner: start scan is blocked
I/BluetoothLeScanner: startRegisteration: mLeScanClients={com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter$1@af4c303=android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper@e577935}
D/EstimoteSDK: com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter.start:248 STARTED SCAN
D/ActivityThread: BDC-Calling onReceive: intent=Intent { flg=0x114 cmp=com.example.selima.beaconmonitoring/com.estimote.sdk.service.BeaconService$ScanAlarmBroadcastReceiver (has extras) }, receiver=com.estimote.sdk.service.BeaconService$ScanAlarmBroadcastReceiver@62af1ca
D/ActivityThread: SVC-Calling onStartCommand: com.estimote.sdk.service.BeaconService@42aeba7, flags=0, startId=9
D/BluetoothAdapter: isEnabled
D/BluetoothAdapter: 90696806: getState(). Returning 12
D/BluetoothAdapter: 90696806: getState(). Returning 12
D/BluetoothAdapter: getLeState() returning 12
D/BluetoothAdapter: STATE_ON
I/BluetoothLeScanner: startRegisteration: mLeScanClients={com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter$1@af4c303=android.bluetooth.le.BluetoothLeScanner$BleScanCallbackWrapper@e577935} ,callback=com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter$1@af4c303
D/EstimoteSDK: com.estimote.sdk.service.internal.bluetooth.LollipopBluetoothAdapter.stop:278 STOPPED SCAN
D/DiscoveredNearables: Discovered nearables: []
D/BluetoothAdapter: getLeState() returning 12
D/TIME: 18:12:24

If it may be useful I can also post the code here