No bluetooth connection, please help

stephankuba

Member
Licensed User
Longtime User
hi,

does someone has a working code for a bluetooth connection. I want to receive string from an other device. No example code in this webside works well. Maybe someone can help me?
Using Android 4.1 or 2.3, Basic4Android version 2.25.

Always problems with error io.iojavaexeption or admin rights or delay by listen to long ......

i do this

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim TextReader1 As TextReader
Dim TextWriter1 As TextWriter
Dim Timer1 As Timer
Dim connected As Boolean

Dim Button1 As Button
Dim serial1 As Serial
Dim ListView1 As ListView
Dim Label1 As Label
Dim mac As String
Dim
Dim txtLog As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("1")
serial1.Initialize("Serial1")


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Down
If serial1.IsEnabled = False Then
Msgbox("Bluetooth nicht aktiv.", "")
End If

Dim PairedDevices As Map
PairedDevices = serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i)) 'add the friendly name to the list
ListView1.AddSingleLine(PairedDevices.GetKeyAt(i))
Next
Dim res As Int
res = InputList(l, "Choose device", -1) 'show list with paired devices
If res <> DialogResponse.CANCEL Then
'serial1.Connect(PairedDevices.Get(l.Get(res))) 'convert the name to mac address
mac = PairedDevices.Get(l.Get(res))
ListView1.AddSingleLine(mac)
serial1.Connect(mac)
End If
Timer1.Enabled = True

End Sub
Sub Timer1_Tick

If TextReader1.Ready Then 'check if there is any data waiting to be read
txtLog.Text = txtLog.Text & TextReader1.ReadLine & CRLF
txtLog.SelectionStart = txtLog.Text.Length
End If

End Sub


thank you:sign0163:
 
Top