Android Question DiscoveryFinished event never stop on kitkat

pin71

Member
Licensed User
Longtime User
Hi Everybody,

I have a problem with the Android KitKat ( 4.4.2). When the bluetooth discovery is finished the system shows the list of devices discovered but if I press in one of them the list of found devices doesn't go away and it seems that the Admin_DiscoveryFinished event keeps happening in loop.

How can I solve it?

Thanks
 

walterf25

Expert
Licensed User
Longtime User
Hi Everybody,

I have a problem with the Android KitKat ( 4.4.2). When the bluetooth discovery is finished the system shows the list of devices discovered but if I press in one of them the list of found devices doesn't go away and it seems that the Admin_DiscoveryFinished event keeps happening in loop.

How can I solve it?

Thanks
It's always better to post at least the relevant part of your code, without looking at it is almost impossible to guess what the cause can be!

Walter
 
Upvote 0

pin71

Member
Licensed User
Longtime User
Here it is :
B4X:
Sub Admin_DiscoveryFinished

   
    If foundDevices.size = 0 Then
        ProgressDialogHide
   
        LabelCONN.Text = mess(17) ' "No devices found."
        'ToastMessageShow("No device found.", True)
    Else
        ProgressDialogHide
        Dim nm As NameAndMac
       
       
        Dim L As List
        L.Initialize
       
        For I = 0 To foundDevices.size - 1
            nm = foundDevices.Get(I)
            L.Add (nm.Name &  nm.Mac )
        Next
       
        Dim res As Int
       
        res = InputList(L,mess(18), -1) '"Choose device to connect"
        If res <> DialogResponse.CANCEL Then
           
            connectedDevice = foundDevices.Get(res)
           
           
            Log("Trying to connect to: " & connectedDevice.Name)
            ProgressDialogShow(mess(20) & connectedDevice.Name & " (" & connectedDevice.Mac & ")")
           
            Serial1.Connect (connectedDevice.Mac)
            MachineMac=connectedDevice.Mac
        End If
    End If
End Sub



Thanks
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Here it is :
B4X:
Sub Admin_DiscoveryFinished

  
    If foundDevices.size = 0 Then
        ProgressDialogHide
  
        LabelCONN.Text = mess(17) ' "No devices found."
        'ToastMessageShow("No device found.", True)
    Else
        ProgressDialogHide
        Dim nm As NameAndMac
      
      
        Dim L As List
        L.Initialize
      
        For I = 0 To foundDevices.size - 1
            nm = foundDevices.Get(I)
            L.Add (nm.Name &  nm.Mac )
        Next
      
        Dim res As Int
      
        res = InputList(L,mess(18), -1) '"Choose device to connect"
        If res <> DialogResponse.CANCEL Then
          
            connectedDevice = foundDevices.Get(res)
          
          
            Log("Trying to connect to: " & connectedDevice.Name)
            ProgressDialogShow(mess(20) & connectedDevice.Name & " (" & connectedDevice.Mac & ")")
          
            Serial1.Connect (connectedDevice.Mac)
            MachineMac=connectedDevice.Mac
        End If
    End If
End Sub



Thanks
Where is the Sub Serial1_Connected (Success As Boolean) method, if you do have it can you see if the device gets connected, do you see any errors in the filtered/unfiltered logs?

B4X:
Sub Serial1_Connected (Success As Boolean)
    ProgressDialogHide
    Log("connected: " & Success)
    If Success = False Then
        Log(LastException.Message)
        ToastMessageShow("Error connecting: " & LastException.Message, True)
    Else
        StartActivity(ChatActivity)
    End If
End Sub

Let me know!
Walter
 
Upvote 0

pin71

Member
Licensed User
Longtime User
Yes, I have exaclty the code that you posted as Serial1 success, and it get connected, but it still prompt the list of devices to select.
Even if I press the back button it doesn't go away.

I put a log in the Admin_DiscoveryFinished Sub and it shows that nomatter what I do, it keep prompting the list of devices found.
This is happening in a Samsung S3 and S4, but in the Note 1 and Note 2 it works perfectly.

Any idea ?


Thanks
 
Upvote 0
Top