connect to non-discoverable bluetooth device

2020-06-17 04:57发布

问题:

I am developing an app for android. Just a general questions as to , if is it possible to connect to a device which is non discoverable publicly?

Thanks in advance.

回答1:

If you have previously paired with the device then it is possible to connect to it again even if it is not in discoverable mode. See this post: programmatically-connect-to-paired-bluetooth-device

    // use paired devices or create a BluetoothDevice using a mac address
    //Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    BluetoothAdapter myAdapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice remoteDevice = myAdapter.getRemoteDevice("00:00:00:00:00:00");
    BluetoothSockt btSocket = remoteDevice.createRfcommSocketToServiceRecord(UUID);
    btSocket.connect();
    //get input and output stream etc...


回答2:

By discoverable I assume you meant responding to device searchs from another device. Some manufacturers also refer to it as visible. Depending on the manufacturer of the device , some devices allow Bluetooth to be on and visibility/discover-ability to be set to off. So if you already know the Bluetooth Address (MAC Address) of the device you can directly connect to it even when the device is not discoverable/visible. In practice it is a good thing to do, many manufacturers allow for this by having the device visible only during specific periods like during the paring process or have explicit menu option to turn on discover-ability for a specific period. This is a good practice from a security stand-point as it prevents device tracking / hacking.

iPhone for example is by default non-discoverable when Bluetooth is on, (but you can still connect to it) it is only discoverable when you enter the Bluetooth menu from the settings menu.



回答3:

It is possible under the Bluetooth standard. I have done this many times connecting two modules from Bluegiga together simply using the MAC address that I knew ahead of time.

Android will let you do this with createInsecureRfcommSocketToServiceRecord