Android Question Bluetooth-connection-problem "java.io.IOException"

D

Deleted member 103

Guest
Hello,

with the first Bluetooth connection I store the MAC address in the settings, so that with the next connection, the connection goes faster.
In the Google Report but always this error comes, and I do not understand why, or I find in my code no errors.

Here is my code:
B4X:
Sub Admin_DiscoveryFinished
    CallSub3(Main,"ShowProgressDialog","",False)
    If foundDevices.Size = 0 Then
        ToastMessageShow(Starter.language.value("strBluetoothNoFound"), True)
    Else
        Dim Macfound As NameAndMac
        Macfound.Initialize
        Macfound.Name = "" 'Sicherstellen das der Name Leer ist.
        
        Dim lst As List
        lst.Initialize
        For i = 0 To foundDevices.Size - 1
            Dim nm As NameAndMac
            nm = foundDevices.Get(i)
            lst.Add(nm.Name)
            
            If Starter.manager.GetString("BtMacAddress") = nm.Mac Then
                Macfound = nm
                Exit
            End If
        Next
        If Macfound.Name <> "" Then
            ConnectToKnownDevice(Macfound)
        Else
            'If lst.Size > 0 Then CallSub2(Main,"ChooseDevice", lst)
            CallSub2(Main,"ChooseDevice", lst)
        End If
    End If
End Sub

Sub ConnectToKnownDevice(BtMac As NameAndMac)
    connectedDevice = BtMac
    CallSub3(Main,"ShowProgressDialog",Starter.language.value("strBluetoothConnect") & " " & BtMac.Name & " (" & BtMac.Mac & ")",True)
    serial1.Connect(BtMac.Mac)
End Sub

and here the crash report:





It would be nice if someone might find the mistake.
 
D

Deleted member 103

Guest
Check that Bluetooth is enabled before you start the discovery process.

That's my code, it should work, right?
B4X:
Main:
Private Sub mnuBtButton_Click  
    bluetooth.ConnectBtButton
End Sub

BT-Class:
Public Sub ConnectBtButton
    If HasFeature("android.hardware.bluetooth") Then
        Try
            If admin.IsEnabled = False Then
                If admin.Enable = False Then
                    ToastMessageShow(Starter.language.value("strBluetoothErrorEnabling"), True)
                Else
                    ToastMessageShow(Starter.language.value("strBluetoothEnabling"), False)
                    'the StateChanged event will be soon raised
                End If
            Else           
                Admin_StateChanged(admin.STATE_ON, 0)
            End If
        Catch
            Log("ConnectBtButton-ERROR:" & LastException)
        End Try
    Else
        ToastMessageShow(Starter.language.value("strBluetoothNotPresent"), True)
    End If
End Sub

Sub Admin_StateChanged (NewState As Int, OldState As Int)
    If NewState = admin.STATE_ON Then
        ToastMessageShow(Starter.language.value("strBluetoothIsEnabled"), False)
        Searchdevice
    End If
End Sub

Sub Searchdevice
    tmpList.Clear
    foundDevices.Clear
    If admin.StartDiscovery    = False Then
        ToastMessageShow(Starter.language.value("strBluetoothErrorProcess"), True)
    Else
        CallSub3(Main,"ShowProgressDialog",Starter.language.value("strBluetoothSearch"),True)
    End If
End Sub
 
Upvote 0
D

Deleted member 103

Guest
After the implementation of crashlytics now these errors come.

I also changed the previous sub "ConnectToKnownDevice", unfortunately without success.
B4X:
Sub ConnectToKnownDevice(BtMac As NameAndMac)
    Try
        connectedDevice = BtMac
        CallSub3(Main,"ShowProgressDialog",Starter.language.value("strBluetoothConnect") & " " & BtMac.Name & " (" & BtMac.Mac & ")",True)
        serial1.Connect(BtMac.Mac)       
    Catch
        Log("ConnectToKnownDevice: " & LastException.Message)
    End Try
End Sub


 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…