2

I would like to programmatically pair my mobile phone with medical sensor using Bluetooth interface. I have address and PIN necessary for connecting to device but I would like to avoid user interaction (pairing process - sensor configuration etc.)

I tried using unofficial Bluetooth API (http://code.google.com/p/android-bluetooth/) but it seems that this doesn't for Android 2.1 and above (I got LocalBluetoothDevice allways NULL, and people on their forum said that this is only for 1.X versions)

I saw that Android API has methods that do this pairing in background but they are labeled with @hide annotation. How do I access this?

Did anyone succeeded in this? (programmatically pairing) Any example?

Thanks!

G K
  • 21
  • 1
  • 1
  • 2

1 Answers1

2

I think you need to use createInsecureRfcommSocketToServiceRecord() which is introduced in API 10. I've got to get this working on Android 2.2, so I used reflection to call the method as per this method & it worked. I am identifying the Bluetooth device I connect to by its friendly name & setting it to not require PIN bonding, my Android APP now connects to it without the device having to be bonded or any PIN input, so its a security concern.

Community
  • 1
  • 1
daveD
  • 869
  • 1
  • 7
  • 24
  • I wonder: How do you force the device to not require a pin? Is this something you'd have to do on the Bluetooth device itself or can it be done from the Android application? – AgentKnopf Feb 17 '12 at 17:17
  • @Zainodis - I think you have to do this on the BT device. – daveD Feb 21 '12 at 11:55
  • Mhhh thanks, thing is we're shipping those devices to customers, we can't manually remove the pin from every device :( . Right now I am going for creating an Rfcomm socket to spawn the pairing dialog (where the user enters the pin) and close the socket right after that. Works well enough for now. – AgentKnopf Feb 21 '12 at 12:04
  • Thsnks Dave you solve my problem as well . You are hero . Thumbs up – Ahmed Aug 08 '12 at 21:20
  • @Gelvis of course this works on 4.0 (coding this right now). However, daveD I want to notice that your solution is not for pairing two devices (i.e. connecting two devices and saving them as a bonded configuration), but just to connect a device to another without need from the latter to accept the connection. (the former still needs to know the destination address, whether through a precedent pairing, a discovery, etc.) – ocramot Mar 19 '15 at 14:51