Android Question Samsung Tab S6 - Android 10 - Bluetooth

lip

Active Member
Licensed User
Longtime User
I've got a problem with Bluetooth admin.StartDiscovery failing. I can see that others have had the same problem and have fixed it by either adding Course location permission, or switching off and on. Neither are working for me yet.

This is very old code, running on all sorts of tablets without a problem. The Galaxy Tab S6 (top-end Android 10 device with Dex etc...) is the first to cause a problem.

My code is in a service which is running. I call it from Main. Not sure what to try next?

Call from Main:
Sub btn_Discover_Click
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_COARSE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("Permission Required for Bluetooth...", False)
        Return
    End If
    CommandEngine.FoundDevices.Clear
    CommandEngine.FoundOtherDevices.Clear
    If CommandEngine.Admin.StartDiscovery = False Then
        ToastMessageShow("Error starting discovery process.", True)
    Else
        ToastMessageShow("Scanning for Bluetooth Devices...", True)
    End If
End Sub

I get "Error starting discovery process." every time.

I've removed and re-allowed the Location permission.

I've switched off and on.

I've paired with the device using the tablet's Bluetooth setting.

I've checked that admin.IsEnabled = True

Any more ideas?

EDIT: I am using B4A 9.90 and I have downloaded the new Bluetooth Chat example (using B4XPages). Same problem: admin.StartDiscovery fails.
 
Last edited:

lip

Active Member
Licensed User
Longtime User
The unfiltered logs are below (using the Chat program). I have also tried a second Tab S6 and get the same result.

Unfiltered Logs:
ViewPostIme pointer 0
ViewPostIme pointer 1
startDiscovery
show: focusDisplayId = 0, isFocusInDesktop = false mCustomDisplayId=-1
SHOW: android.widget.Toast$TN@abb58e3
HANDLE SHOW: android.widget.Toast$TN@abb58e3 mView=null mNextView=android.widget.LinearLayout{96c32e0 V.E...... ......I. 0,0-0,0}
HANDLE HIDE: android.widget.Toast$TN@abb58e3 mView=null
setView = android.widget.LinearLayout@96c32e0 TM=true MM=false
Text: Frro in android.widget.Toast$TN@abb58e3
Relayout returned: old=(0,0,2560,1491) new=(1322,1400,1766,1477) req=(444,77)0 dur=6 res=0x7 s={true 504201060352} ch=true
createReliableSurface : 0x75b5f0e580(0x7564b9a000)
makeCurrent EglSurface : 0x75c6eeaf00 -> 0x7658540b00
makeCurrent EglSurface : 0x7658540b00 -> 0x75c6eeaf00
MSG_RESIZED: frame=(1322,1400,1766,1477) ci=(0,0,0,0) vi=(0,0,444,77) or=2
HIDE: android.widget.Toast$TN@abb58e3
HANDLE HIDE: android.widget.Toast$TN@abb58e3 mView=android.widget.LinearLayout{96c32e0 V.E...... ........ 0,0-444,77}
REMOVE! android.widget.LinearLayout{96c32e0 V.E...... ........ 0,0-444,77} in android.widget.Toast$TN@abb58e3
destroyEglSurface : 0x7658540b00
~ReliableSurface : 0x75b5f0e580
dispatchDetachedFromWindow
Input channel destroyed: '1949316', fd=81
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
I've added the unfiltered logs to the Post. Also note that "Make device discoverable" works.

When Discovery fails, I've tried calling Serial.Connect(MAC) with a known, available, paired MAC. The Serial_Connected() event does not fire.
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
BluetoothAdmin.StartDiscovery just calls the underlying native API. It might be an OS issue. Try to disable and enable Bluetooth. It might help.

Thanks for continued support Erel...

I've tried Bluetooth off and on. Power off and on. I've tested the Bluetooth functionality of the tablet to death using Settings and it's fine, including Scan.

I've hard coded a direct connection (below) and with this in place the Bluetooth Chat program works perfectly (Except for "Search for Devices) and I can chat to other tablets, phones, devices etc.

It all points to permissions, but I can see clearly that the Location permission is granted. 3 Days at it, and I stumped.

Did the "Input Channel Destroyed" log at the end of the unfiltered logs tell you anything? The rest seem to be just logs relating to the ToastMessage.

Hard Coded Mac Address Works:
Sub btnSearchForDevices_Click
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_COARSE_LOCATION)
    Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        ToastMessageShow("No permission...", False)
        Return
    End If
    Dim success As Boolean = admin.StartDiscovery
    If success = False Then
        ToastMessageShow("Error starting discovery process.", True)
        BTMac = "88:9F:6F:79:66:1F"
        Log("Direct Connect to " & BTMac)
        serial.Connect(BTMac)
    Else
        CLV.Clear
        Dim Index As Int = ShowProgress
        Wait For Admin_DiscoveryFinished
        HideProgress(Index)
        If CLV.Size = 0 Then
            ToastMessageShow("No device found.", True)
        End If
    End If
End Sub
 
Upvote 0

lip

Active Member
Licensed User
Longtime User
FIXED !!!

Can't explain why, but with the Samsung Tab S6 ONLY:-

Calling this from the Main activity fails:
ServiceModule.Admin.StartDiscovery

However calling this from Main works:
Callsub(ServiceModule,"StartDiscovery")

And then within the Service Module:
Sub StartDiscovery
Admin.StartDiscovery
...
 
Upvote 0
Top