Android Question bluetooth connection failure

RichyK68

Active Member
Licensed User
Longtime User
Hi all,

I have two apps, A and B. App A runs on device A, app B runs on device B. I want them to communicate via Bluetooth. Both devices have Bluetooth enabled and are already paired, so I don't need to worry about that, it should just be a simple connection request (I thought) from one device to the other.

It's a simple one-way link between the two apps. A sends messages to B, B doesn't need to respond.

App A does

Sub Process_Globals

Dim BT As BluetoothAdmin
Dim Serial1 As Serial
Dim TextWriter1 As TextWriter
Dim SerialTimer1 As Timer
Dim Connected As Boolean

End Sub

Sub Service_Create

BT.Initialize("BT")
BT.Enable
Serial1.Initialize("Serial1")
SerialTimer1.Initialize("SerialTimer1",500)

end sub

sub whenineedtosendamessage

If Serial1.IsEnabled Then
Serial1.Connect("50:46:5D:78:6B:7B")
end if

end sub

Sub Serial1_Connected (Success As Boolean)

If Success Then
ToastMessageShow("Connected successfully", False)
TextWriter1.Initialize(Serial1.OutputStream)

SerialTimer1.Enabled = True
Connected = True
TextWriter1.WriteLine("hello world")
TextWriter1.Flush
Else
Connected = False
SerialTimer1.Enabled = False
ToastMessageShow("Error connecting.", False)
End If

End Sub

App B does the same in Process_Globals and this :

Sub Service_Create

BT.Initialize("BT")
BT.Enable

Serial1.Initialize("serial1")
if serial1.IsEnabled then Serial1.Listen ' the listen is definitely executing (it doesn't error)

end sub

The problem is, when method whenineedtosendamessage is called in app A, the toast message "Error connecting." appears. The MAC address I am using is definitely the address for the device app B is running on. Like I said, Bluetooth is enabled on both devices, they are already paired.

Any ideas why I'd get a connection failure?

Richard
 
Top