connect to non-discoverable bluetooth device

只愿长相守 提交于 2019-12-04 03:43:22
Alex

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...

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!