Android Question Bluetooth createbond and removebond

Discussion in 'Android Questions' started by SteveTerrell, Feb 10, 2015.

  1. SteveTerrell

    SteveTerrell Active Member Licensed User

    Hi,

    does anyone have any experience using these api's to programatically pair and unpair Bluetooth devices. Presumably they can be accessed with the reflection library or perhaps even better with inline java code?

    The resulting effects paired/unpaired look easy to catch with the broadcast receiver.

    Are there any tricky bits to watch out for?
    For instance, does the createbond api pop up the pairing code window?
     
  2. SteveTerrell

    SteveTerrell Active Member Licensed User

    For those that are interested, this code unpairs a device when its mac address is known. It works on my HC-06 module.
    It has a lot of my debugging Log's in which will not be needed and the mac address will usually not be a literal string.
    The "removeBond" method is accessible but not public according to my research on the web.

    Code:
    Dim joa As JavaObject
        joa = joa.InitializeStatic(
    "android.bluetooth.BluetoothAdapter").RunMethod("getDefaultAdapter"Null)

        
    Log(joa.RunMethod("getName"Null)) ' gets my BT name - just checking
       
    Dim job As JavaObject
        job = joa.RunMethod(
    "getRemoteDevice"Array As String ("98:D3:31:30:2C:04")) ' mac address of remote BT
        ' after this "job" has the object that is the remote device

        
    Log(job.RunMethod("getName"Null)&" is "&BondStateToString(job.RunMethod("getBondState"Null)))
        
    ' gets the friendly name of the remote BT as a check

        
    ' see if unpair call works
        If job.RunMethod("removeBond"NullThen
            
    Log("Remove true")
        
    Else
            
    Log("Remove false")
        
    End If
    If anyone wants to offer a more elegant version of this I would be only too pleased to see it.
     
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