Android Question How can I tell which blue tooth devices are connected with the tablet

Discussion in 'Android Questions' started by davepamn, Apr 6, 2015.

  1. davepamn

    davepamn Active Member Licensed User

    I need to know which blue tooth devices are connected with the tablet when my app starts.

    After I connect the first time then close my app and reopen it, I get "No blue tooth Devices Found" because they are not discovered.

    The Zebra GX420d display is showing the "Blue Tooth is connected"

    Code:
    Sub btnBlueToothConnect_Click

      admin.Initialize(
    "Admin")


      
    If admin.StartDiscovery= False Then
          
    ToastMessageShow("Error starting discovery process."True)
      
    Else
           
    ProgressDialogShow("Searching for devices...")
      
    End If

      
    Dim Tablet As PhoneWakeState

      Tablet.KeepAlive(
    True)

    End Sub

    Sub Admin_DeviceFound (Name As String, MacAddress As String)

    'Log(Name & ":" & MacAddress)

    Dim nm AsNameAndMac

    If nm.IsInitialized=False Then

      nm.Initialize

    End If


    nm.Name = Name

    nm.Mac = MacAddress

    foundDevices.Add(nm)

    ProgressDialogShow("Searching for devices (~ device found)...".Replace("~", foundDevices.Size))

    End Sub


    Sub Admin_DiscoveryFinished

    Try

    ProgressDialogHide

    If foundDevices.Size = 0 Then

       
    ToastMessageShow("No blue tooth devices found."True)

    Else

    Dim l As List

    l.Initialize

    For i = 0 To foundDevices.Size - 1

    Dim nm AsNameAndMac

    If nm.IsInitialized=False Then

       nm.Initialize

    End If

    nm = foundDevices.Get(i)

    l.Add(nm.Name)

    Next

    Dim res As Int

    Dim connectedDevice As NameAndMac

    res = 
    InputList(l, "Choose device to connect", -1)

    If res <> DialogResponse.Cancel Then

    connectedDevice = foundDevices.Get(res)

    ProgressDialogShow("Trying to connect to: " & connectedDevice.Name & " (" & connectedDevice.Mac & ")")

    ProgressDialogHide

    serial1.Connect(connectedDevice.Mac)

    If AStream.IsInitialized = False Then

    AStream.InitializePrefix(serial1.InputStream, 
    True, serial1.OutputStream, "AStream")

    End If

    End If

    End If

    Catch

    oError.ShowLastException(
    "Error : TestAdmin_DiscoveryFinished")

    EndTry

    End Sub


    Sub AStream_NewData (Buffer() As Byte)

    Log(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))

    End Sub

    Sub AStream_Error

    ToastMessageShow("Connection is broken."True)

    End Sub


    Sub AStream_Terminated

    AStream_Error

    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Connections cannot be shared between different apps. You must find the device and connect to it from your app.
     
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