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

Discussion in 'Android Questions' started by Filippo, Oct 22, 2018.

  1. Filippo

    Filippo Expert Licensed User

    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:
    Code:
    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:
    b41.PNG

    b42.PNG

    It would be nice if someone might find the mistake.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Worth adding a Try / Catch block around this call.

    I know that it doesn't sound too reasonable, however are you checking that Bluetooth is enabled?
     
    Filippo likes this.
  3. Filippo

    Filippo Expert Licensed User

    I will try it

    No, that did not check
     
  4. Erel

    Erel Administrator Staff Member Licensed User

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

    Filippo Expert Licensed User

    That's my code, it should work, right?
    Code:
    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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't see any error.
     
    Filippo likes this.
  7. Filippo

    Filippo Expert Licensed User

    me too. :p
    The problem is that the customers see what. :(
    I myself can not reproduce the mistake.
     
  8. Filippo

    Filippo Expert Licensed User

    After the implementation of crashlytics now these errors come.

    I also changed the previous sub "ConnectToKnownDevice", unfortunately without success.
    Code:
    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
    upload_2018-10-26_7-43-49.png

     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Are you sure that this error happened after you added the Try / Catch block? It should catch IOException errors.
     
  10. Filippo

    Filippo Expert Licensed User

    If you ask, I'm not so sure anymore, I'll wait a few more days. :confused:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice