Android Question Problem with BLE in Android 7 & 8

Jaume Guillem

Member
Licensed User
Longtime User
Hi.
I have a curious problem using BLE with Android 7 & 8.

Mi app worked for years in versions 6 and lower of Android, and with Bluetooh 3 and BLE. Allways without problems.

I introduced the necessary modifications to run Android 7 and 8.

Manifest:
B4X:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="27"/>
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddPermission(android.permission.ACCESS_FINE_LOCATION)

B4X:
Sub Activity_Create(FirstTime As Boolean)
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
....
end sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
   Select Case Permission
   Case rp.PERMISSION_WRITE_EXTERNAL_STORAGE
              If Result Then
                    ToastMessageShow("Permission OK",True)
              End If
     Case rp.PERMISSION_ACCESS_FINE_LOCATION
               If Result Then
                     ToastMessageShow("BT Permission OK",True)
               End If
            End Select
End Sub

It produces a curious effect ONLY running in a device with Android 7 (and 8 I suppose)

After scanning, the Manager_DeviceFound is fired correctly

B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
        If Id=Starter.StoredId then
                manager.Connect2(Id,False)
        end if
end sub

But Immediately after Connect2 (and Connect also), the event fired is Manager_Disconnected
(instead of Manager_Connected)

If I run the app in a phone with Android 4 or 5, all is working perfect.

And I don’t know how to manage this. Any idea?
I’m using B4A 8.0 and BLE2 V 1.36

Thank you very much
 

Jaume Guillem

Member
Licensed User
Longtime User
Thanks for the idea, but it does not work. Same problem.
The behavior of the example and my app is the same (after putting sdk = 26)
I tried with three different devices and always the same. Scan is correct, but when I call manager.Scan2(Null, False) , the event fired is Manager_Disconnected

This is with a BM77 (a Microchip device)
B4X:
Logger connected to:  samsung SM-J530F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: b4a.example.customlistview, trying: b4a.example3.customlistview
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
** Activity (main) Resume **
Found: Test 1          , 34:81:F4:14:B1:D9, RSSI = -59, (MyMap) {1=[B@367ab89, 9=[B@e5df78e, 0=[B@543dbaf}
Disconnected
Found: Test 1          , 34:81:F4:14:B1:D9, RSSI = -64, (MyMap) {1=[B@1fc83cb, 9=[B@2ae27a8, 0=[B@82c42c1}
Disconnected

and this with a Contour (a glucose monitor)
B4X:
** Activity (main) Resume **
Found: Contour7801H5104382, 24:71:89:0D:75:39, RSSI = -47, (MyMap) {1=[B@fb4bd53, 2=[B@2d61690, -1=[B@367ab89, 9=[B@e5df78e, 0=[B@543dbaf}
Disconnected
Found: Contour7801H5104382, 24:71:89:0D:75:39, RSSI = -48, (MyMap) {1=[B@1fc83cb, 2=[B@2ae27a8, -1=[B@82c42c1, 9=[B@9756a66, 0=[B@e4d91a7}
Disconnected

Testing more than thirty times, ONE connection has been successful.
I tried to delay the connection one or two seconds, in case this was the problem, but there is no variation.

Trying SDK=21 and lower, the problem persist.
The phone is a Samsung J5 2017 with Android 7.
With a Samsung S4 Android 4.4.2 works perfect

Thanks for your help
 
Upvote 0
Top