Android Question BLE2 Can't Connect on newer Android versions

Turbo3

Active Member
Licensed User
The BLE2 example code runs on a device with Android 5.1 (API 22). However when I run the exact same example on a device which has Android 7.0 (API 24) it does not connect.

What I notice is that on the working device I see a log message from BLE2 of "Discovering services.' after executing "manager.Connect2(Id, False)" but on the newer device there is no such message and a connected event is never raised.

This is on a new PC with a new install of everything as per the latest install instructions.

BLE2 is version 1.37
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
B4A is 8.50 BETA #1
javac.exe is jdk1.8.0_181
android.jar is android-27

Just swapped between two Moto phones running 5.1 and 7.0.
 

Turbo3

Active Member
Licensed User
It looks to be the same problem as reported here but there was no followup by poster.

https://www.b4x.com/android/forum/threads/ble2-cant-connect.96189/

================
Update: My tester in Japan has just tested an app I sent him with the same BLE code and was able to get it to work. This was on a Samsung S7 edge with Android 7.0. But my Moto G5 Plus with Android 7.0 always fails.

Can more debug messages be added to BLE2 in the Connect code before it sends the "Discovering Service" debug message? That would help locate where things are getting hung up.
 
Last edited:
Upvote 0

Turbo3

Active Member
Licensed User
Here are three logs. One from Android 5 phone that works and two from Android 7 phone that fails.

I added two lines to the Manager_DeviceFound code to connect only to "OBDBLE" and to Log when trying to connect.

B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
    Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
    If Name<>"OBDBLE" Then Return
    ConnectedName = Name
    manager.StopScan
    manager.Connect2(Id, False) 'disabling auto connect can make the connection quicker
    Log("Trying to connect to "&Name)
End Sub
 

Attachments

  • BLE Example Logs.zip
    14.2 KB · Views: 80
Upvote 0

Turbo3

Active Member
Licensed User
1. Adding Sleep(1000) did not help

2. Ran a BLE app from Google Play and it also failed to connect.

3. Rebooted phone and now both the Google Play app and the B4A BLE example app are now working.

I normally cycle Bluetooth off and on to clear any bad connections but I guess that did not help in this case. A full power cycle was needed to clear whatever was blocking the connection from working.

Thanks for pointing me in the right direction. This is a much better solution and explains why my tester with Android 7 did not have the same problem.
 
Upvote 0
Top