How to create Insecure RFCOMM Socket in Android?

createInsecureRfcommSocketToServiceRecord() was included starting with Android API Level 10, so the documentation will encourage you to use it since the docs always follow the latest version of the API. If you are targeting an API lower than 10 (a.k.a. 2.3.3 or Gingerbread), then that method is not publicly accessible to you.

The method you are calling via reflection createInsecureRfcommSocket() is a private method inside BluetoothDevice that has been present since roughly Android 2.0. The problem with calling hidden methods is that they aren’t guaranteed to be there on all devices, or in the future…so you’re gambling a bit. My guess is your method will probably work most of the time on most 2.0+ devices, since the services required to implement its public cousin createRfcommSocketToServiceRecord() are so similar at the stack layer.

Bottom line, if you want guaranteed universal compatibility with your Bluetooth implementation, you’ll have to target 2.3.3 (API Level 10) with your application. With a public API now exposed for insecure RFCOMM, it’s hard to say whether it’s more or less likely for the underlying private implementation to change.

Leave a Comment