This is a second attempt to articulate a problem I'm having pairing a Bluetooth device to a Samsung tablet. This code works on other tablets and devices, including my phone, which is also running Android 9.
The problem is that on the Samsung Galaxy Tab A the process errors with a timeout before the pairing code can be inputted. The code is attached. Below are two logs: The first is a successful pairing on an older Samsung tablet. The second is the same code running on the problem tablet in the subject line.
I'd appreciate any help you can offer. I'm out of ideas.
Log from Samsung Galaxy Tab S SM-T800 running Android 6.0.1
Pairing successful
--------------------------------------------------------
device found : 5F:20:89:85A:2B
device found Se3a4cf18020f8a9eC : 84:EE:03:49:1F:59
device found : 44:31:69:4C:6B:58
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
selected device name = 0503:00061BDF:Vemco Field Reader
** Activity (configbt) Pause, UserClosed = false **
** Activity (configbt) Resume **
Stored to external file: 10:00:E8:C2:E2:A4
** Activity (configbt) Pause, UserClosed = true **
** Activity (main) Resume **
Log from Samsung Galaxy Tab A SM-T510 running Android 9
Pairing NOT successful - failed before pairing code could be entered
-----------------------------------------------------------
device found : 44:31:69:4C:6B:58
device found Se3a4cf18020f8a9eC : 84:EE:03:49:1F:59
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found : 6CA:AF:9B:8B:AE
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found TVBluetooth : C4:73:1E:5FF:F6
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found TVBluetooth : C4:73:1E:5FF:F6
selected device name = 0503:00061BDF:Vemco Field Reader
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
** Activity (configbt) Pause, UserClosed = true **
** Activity (main) Resume **
The problem is that on the Samsung Galaxy Tab A the process errors with a timeout before the pairing code can be inputted. The code is attached. Below are two logs: The first is a successful pairing on an older Samsung tablet. The second is the same code running on the problem tablet in the subject line.
I'd appreciate any help you can offer. I'm out of ideas.
B4X:
#
#Region Activity Attributes
#FullScreen: True
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim admin As BluetoothAdmin
Dim serial1 As Serial
Dim foundDevices As Map
Type NameAndMac (Name As String, Mac As String)
Dim connectedDevice As NameAndMac
End Sub
Sub Globals
Dim btnSearchForDevices As Button
Dim btnDeleteDevices As Button
Dim btnDone As Button
Dim lblCurrentDevice As Label
Dim lstBT As List
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
admin.Initialize("admin")
serial1.Initialize("serial1")
End If
Activity.LoadLayout("configbt")
End Sub
Sub Activity_Resume
ShowDevices
btnSearchForDevices.Enabled = False
If admin.IsEnabled = False Then
If admin.Enable = False Then
ToastMessageShow("Error enabling Bluetooth adapter.", True)
Else
ToastMessageShow("Enabling Bluetooth adapter...", False)
End If
Else
Admin_StateChanged(admin.STATE_ON, 0)
End If
End Sub
Sub Admin_StateChanged (NewState As Int, OldState As Int)
btnSearchForDevices.Enabled = (NewState = admin.STATE_ON)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed = True Then
serial1.Disconnect
End If
End Sub
Sub btnSearchForDevices_Click
foundDevices.Initialize
If admin.StartDiscovery = False Then
ToastMessageShow("Error starting discovery process.", True)
Else
ProgressDialogShow("Searching for devices...")
End If
End Sub
Sub Admin_DeviceFound (Name As String, MacAddress As String)
Log("device found " & Name & " : " & MacAddress)
Dim mapValue As NameAndMac
mapValue.Name = Name
mapValue.Mac = MacAddress
foundDevices.Put(Name, mapValue)
End Sub
Sub Admin_DiscoveryFinished
ProgressDialogHide
If foundDevices.Size = 0 Then
ToastMessageShow("No device found.", True)
Else
Private lstFound As List
lstFound.Initialize
For Each nm As NameAndMac In foundDevices.Values
lstFound.Add(nm.name)
Next
InputListAsync(lstFound, "Choose device to connect", -1, True)
Wait For InputList_Result (res As Int)
If res <> DialogResponse.CANCEL Then
Log("selected device name = " & lstFound.Get(res))
connectedDevice = foundDevices.GetValueAt(res)
ProgressDialogShow("Trying to connect to: " & connectedDevice.Name & " (" & connectedDevice.Mac & ")")
serial1.Connect(connectedDevice.mac)
End If
End If
End Sub
Sub Serial1_Connected (Success As Boolean)
ProgressDialogHide
If Success = False Then
Log(LastException.Message)
ToastMessageShow("Error connecting: " & LastException.Message, True)
Else
lstBT.Add( connectedDevice.Mac )
File.WriteList( File.DirDefaultExternal, "BT-Vemco-FieldReader.txt", lstBT )
Log("Stored to external file: " & connectedDevice.Mac)
ShowDevices
ToastMessageShow( "Bluetooth Configuration Saved", False )
serial1.Disconnect
End If
End Sub
Sub btnDeleteDevices_Click
If lstBT.Size > 0 Then
For i = 0 To lstBT.Size - 1
UnpairDevice(lstBT.Get(i))
Next
End If
If File.Exists( File.DirDefaultExternal, "BT-Vemco-FieldReader.txt" ) Then
File.Delete(File.DirDefaultExternal, "BT-Vemco-FieldReader.txt")
lstBT.Initialize
End If
ShowDevices
ToastMessageShow( "Bluetooth Devices Removed", False )
End Sub
Sub UnpairDevice(Address As String)
Dim adapter As JavaObject
adapter = adapter.InitializeStatic("android.bluetooth.BluetoothAdapter").RunMethod("getDefaultAdapter", Null)
Dim device As JavaObject = adapter.RunMethod("getRemoteDevice", Array(Address))
Log(device.RunMethod("removeBond", Null))
End Sub
Sub btnDone_Click
serial1.Disconnect
Activity.Finish
End Sub
Sub ShowDevices
If File.Exists( File.DirDefaultExternal, "BT-Vemco-FieldReader.txt" ) Then
Private DeviceList = "" As String
Private FoundThisOne = False As Boolean
serial1.Initialize("serial1")
Private PairedDevices As Map
PairedDevices = serial1.GetPairedDevices
lstBT = File.ReadList(File.DirDefaultExternal, "BT-Vemco-FieldReader.txt")
For i = 0 To lstBT.Size - 1
For pd = 0 To PairedDevices.Size - 1
If PairedDevices.GetValueAt(pd) = lstBT.Get(i) Then
DeviceList = DeviceList & PairedDevices.GetKeyAt(pd) & " (" & lstBT.Get(i) & ")" & CRLF
FoundThisOne = True
End If
Next
If FoundThisOne = False Then
DeviceList = DeviceList & "Unpaired device at " & lstBT.Get(i) & CRLF
End If
Next
lblCurrentDevice.Text = "Current Device(s): " & CRLF & CRLF & DeviceList
Else
lstBT.Initialize
lblCurrentDevice.Text = "No Devices"
End If
End Sub
Log from Samsung Galaxy Tab S SM-T800 running Android 6.0.1
Pairing successful
--------------------------------------------------------
device found : 5F:20:89:85A:2B
device found Se3a4cf18020f8a9eC : 84:EE:03:49:1F:59
device found : 44:31:69:4C:6B:58
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
selected device name = 0503:00061BDF:Vemco Field Reader
** Activity (configbt) Pause, UserClosed = false **
** Activity (configbt) Resume **
Stored to external file: 10:00:E8:C2:E2:A4
** Activity (configbt) Pause, UserClosed = true **
** Activity (main) Resume **
Log from Samsung Galaxy Tab A SM-T510 running Android 9
Pairing NOT successful - failed before pairing code could be entered
-----------------------------------------------------------
device found : 44:31:69:4C:6B:58
device found Se3a4cf18020f8a9eC : 84:EE:03:49:1F:59
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found : 6CA:AF:9B:8B:AE
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found TVBluetooth : C4:73:1E:5FF:F6
device found 0503:00061BDF:Vemco Field Reader : 10:00:E8:C2:E2:A4
device found TVBluetooth : C4:73:1E:5FF:F6
selected device name = 0503:00061BDF:Vemco Field Reader
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
** Activity (configbt) Pause, UserClosed = true **
** Activity (main) Resume **
Last edited: