[ACCEPTED]-How to create Insecure RFCOMM Socket in Android?-insecure-connection

Accepted answer
Score: 29

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

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

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

Score: 5

Well most of replied answers here, are before 9 March 30 2011, in this post.

While looking 8 for the solution of similar problem in my 7 app, I have found this blog written on March 6 30.

It will help all those who are still 5 looking for this problem solution on SO 4


The solution has become very simple now. Just 3 include InsecureBluetooth.java in your project 2 and change 2 lines in BluetoothChatService.java.

tmp = InsecureBluetooth.listenUsingRfcommWithServiceRecord(mAdapter, NAME, MY_UUID, true);

and 1

tmp   = InsecureBluetooth.createRfcommSocketToServiceRecord(device, MY_UUID, true);

Thats it !

More Related questions