Android: Any way to auto-pair to another device over Bluetooth without prompting for a pin?
I am looking for a way to connect to Android devices via Bluetooth without user intervention(assuming at least on device is set to "Discoverable"). Since 2.0, it seems the devices prompt for a random pin to be entered wh开发者_如何学Goen connecting to each other for the first time. I've tried some Bluetooth projects, but none seem to work as the underlying Bluetooth Adapter code always kicks in.
Is there any way around this? Thanks.
As Janusz explains, it's not possible to automatically pair to a different device, but it might be possible to communicate with the other device without having to pair. From API level 10 onwards, the BluetoothDevice.createInsecureRfcommSocketToServiceRecord method and matching BluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord method allow you to create an "insecure" RFCOMM channel to connect the two devices, without pairing them. This channel is vulnerable to a man-in-the-middle attack: any other device might intercept the connection, allowing it to read every message and replace messages with its own. That may or may not be a problem for your application. Note also that this only allows you to establish RFCOMM channels this way: it doesn't let you connect to (for example) a headset without pairing.
If you already know the address of the other device, you can do this without either device being discoverable.
This should not be possible because it would be a security issue. This would allow a bluetooth device to connect to you phone and extract contacts etc. without you ever noticing. A User Intervention should always be necessary for the first pairing.
精彩评论