Android Question Bluetooth Discovery return 0 devices

PetarS

New Member
Licensed User
Hi, I'm new here, and have very little experience with B4A.
Few years back I wrote simple application to connect to Bluetooth serial device(SPP).
Now I need similar thing, so I buy new version of B4A, used same code and have mixed results.
On galaxy s1 and s3 I see device in list, on S2, S6 and S7 returned list is always empty.
I tried to run with debugger, I run same .apk on every phone, and results are same.
S1 and S3 works, other doesn't.
When I install old .apk file I can connect on every device.
Here is code that I used to connect to Bluetooth.
B4X:
Sub BTAdmin_DeviceFound (Name As String, MacAddress As String) 'Newer rises on s2 s6 s7
    log(Name & ":" & MacAddress)
    Dim nm As NameAndMac
    nm.Name = Name
    nm.Mac = MacAddress
    foundDevices.Add(nm)
    ProgressDialogShow("Searching for devices (~ device found)...".Replace("~", foundDevices.Size))
End Sub

Sub BTAdmin_DiscoveryFinished
    ProgressDialogHide
    
        Dim l As List
        l.Initialize
        For i = 0 To foundDevices.Size - 1
            Dim nm As NameAndMac
            nm = foundDevices.Get(i)
            l.Add(nm.Name)
        Next
        l.Add("Search nearby devices")
        Dim res As Int
        res = InputList(l, "Choose device to connect", -1)
        If res <> DialogResponse.CANCEL Then
            If res<l.Size-1 Then 
                connectedDevice = foundDevices.Get(res)
                ProgressDialogShow("Trying to connect to: " & connectedDevice.Name)
                serial1.Connect(connectedDevice.Mac)
                Connected=True
            Else
                foundDevices.Initialize
                If BTAdmin.StartDiscovery = False Then
                    ToastMessageShow("Error starting discovery process.", True)
                    tbStatus.Checked=False
                Else
                    ProgressDialogShow("Searching for devices...")
                End If
            End If
        Else
            tbStatus.Checked=False
        End If
Java:
C:\Program Files\Java\jdk1.8.0_172\bin\javac.exe
Android SDK:
D:\Android\android-sdk\platforms\android-25\android.jar
Did I leave any important details?
Do I need to add some permission or something like that?
Any other idea?
Thanks
 

PetarS

New Member
Licensed User
Thanks for quick reply.
I'll look example and try it during next week.
Here is copy of manifest:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.
 
Upvote 0
Top