Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 6.0 won't connect to BLE device anymore after turning bluetooth off and back on again

I've written an app that scans for bluetooth smart devices, you can pick one from a list, connect to it and exchange some data. All went fine until Android 6.0.

First, i fixed the new permission system so the app requests the location permission at runtime to be able to scan for devices. With that the app worked like it used to, but after turning bluetooth off and back on again the app won't connect anymore but always returns disconnected state with status code 133 in the gatt callback.

I then tried several things:

  • rebooted the device
  • re-installed the app
  • turn off wifi, enable / disable flight mode
  • checked with NRF master control panel, same issue with same statuscode

This all didn't solve the problem. The only way i was able to get it working again was the option "Network Settings Reset" from the menu "Backup & reset". Both development phones available here (Moto G3 and Samsung S6) feature this option, haven't seen it before Android 6.0.

My question is: are there others experiencing this problem and is there a fix or workaround for this? This could cause a lot of troubles, it so common to turn off /on bluetooth and the problem also appears after been in flight-mode.

like image 948
JPS Avatar asked Nov 08 '22 18:11

JPS


1 Answers

Ok, so after a while i tackled this. I was working with NRF ble devices and could not connect but i was still able to connect to TI sensorTag devices.

There were some differences between the advertisements of the devices, some flags were not enabled for the NRF device and also the NRF device had no device name set. After changing this, i was able to connect again. Turned out that devicename must be enabled but can be left empty.

It seems in the Android 6.0 ble stack there is a change in how the connection to a device is made, the device is not connectable anymore if not the right advertisement settings are used after bluetooth is turned off and on again.

like image 101
JPS Avatar answered Nov 14 '22 21:11

JPS