Pairing SPP bluetooth devices with Android phones

Update: I have turned the below class into an app which I’ve made available in the Google Play Store called Bluetooth Class Zero. It is a simple application which just enables pairing with bluetooth class zero devices without having to root & patch your phone.

————————————–

I bought a Bluetooth Bee from Seeed Studios, which is an SPP (Serial Port Profile) bluetooth device, with the intention of writing an app for Android that communicates with a remote data logger. Unfortunately, it turns out that there’s a bug in the BroadComm bluetooth stack that is used by most Android phone manufacturers (LG, HTC, Samsung are affected, but not the Google Nexus phones) that prevents discovery to this and all other bluetooth devices that report their Class of Device (CoD) code as 0×00. This is the case for many SPP bluetooth devices, and SPP is probably the most common bluetooth profile (at least it’s the most basic – just straight serial comms) so this bug is pretty nasty.

Basically, if you perform a scan for devices, your SPP device will not show up, and in the logs you will see:

ERROR/DTUN_HCID4(663): Device [00:18:E4:0C:6E:CA] class is 0×00 – skip it.

The code for the Broadcom bluetooth stack is open source, so the bug is plain for all to see here. The bug has been reported on StackOverflow and elsewhere.

Until Broadcom and/or all users of their bluetooth stack fix this issue (by simply removing the IF block that skips devices whose CoD is 0×00), the only way to connect to your SPP device from Android is to read the log files, looking for the above error, extract the device address, and manually initiate a connection in code. After this, your SPP device will appear along with all your other bluetooth devices in the bluetooth settings page on your phone, and you can successfully communicate using the bluetooth API provided by Google.

I have written a re-usable class that implements this workaround, which you can download from here.

How to use (from your Activity class):

(new BluetoothClassZeroDiscoveryTask(
    this, 
    new BluetoothDiscoveryCallback())).execute();

Where BluetoothDiscoveryCallback is a class defined e.g. in your Activity. The call method will be called after the discovery task completes, and is passed the complete list of paired bluetooth devices, including those that are undiscoverable due to the above bug.

private class BluetoothDiscoveryCallback
    implements Action<ArrayList<BluetoothDevice>>
{
	public void call(ArrayList<BluetoothDevice> devices)
	{
		// Now you have the list of ALL available devices, 
		// including those that report class 0x00.
	}
}

// Java equivalent of the built-in Action from C#.
public interface Action<T>
{
	void call(T target);
}

You’ll also need to add READ_LOGS permission to your manifest file:

<uses-permission android:name="android.permission.READ_LOGS" />

Feel free to suggest improvements to the code, I’m new to Android and haven’t done Java in ages :)

P.S. Hassle your phone manufacturer to fix this bug so this workaround is not needed!

App Screenshots:

After pressing “Start Discovery”, if any bluetooth class zero devices were found (but ignored), you will get the standard pairing dialog:

After entering the correct PIN code, your device will be listed alongside others in your bluetooth settings:

The app requires Android 2.1+. It’s been tested on the following phones:


Manufacturer Model Android Version Affected Results
LG Optimus One 2.2 Yes Works
HTC Desire HD 2.2 Yes Works, but unfortunately may interfere with networking / bluetooth operation.
Samsung Galaxy S (I9000) 2.2 Yes Fails
Samsung Galaxy Player 50 2.1 Yes Works

The app is free to use, if you find it useful, feel free to make small donation :)

  1. TheBeano says:

    This is an interesting and creative hack. For what it’s worth I tried my Seeedstudio bluetooth module with the SGS and it did scan and pair up OK. I’m using Samsung’s Android 2.3.3, (JVO version). I’m not sure if this means they’ve fixed the bug (probably not!) or the Seeedstudio module I have is different. I have a DFRobot bluetooth module that works as well. They’re both based on the CSR BlueCore chips.

    • Benjamin says:

      HI, got the same module and I was unable to discover it. My PC can but my phone doesn’t. Did you use Arudino for controlling the device?

  2. TheBeano says:

    This is an interesting and creative hack. For what it’s worth I tried my Seeedstudio bluetooth module with the SGS and it did scan and pair up OK. I’m using Samsung’s Android 2.3.3, (JVO version). I’m not sure if this means they’ve fixed the bug (probably not!) or the Seeedstudio module I have is different. I have a DFRobot bluetooth module that works as well. They’re both based on the CSR BlueCore chips.

    • Benjamin says:

      HI, got the same module and I was unable to discover it. My PC can but my phone doesn’t. Did you use Arudino for controlling the device?

  3. bob says:

    What about the Samsung galaxy tab? I cant pair any by devices

  4. bob says:

    What about the Samsung galaxy tab? I cant pair any by devices

  5. José Lima says:

    Hello.

    Congratulations for your App it seems to be very useful.

    However I have an HTC Desire and i was trying to pair it with the Bluetooth Bee form SeedStudio but it wasn’t posible due to the issue that you reported. Even with your application i’m able to pair it but when i iitiate the serial communication it starts to become buggy.

    Do you have any solution for this?

  6. José Lima says:

    Hello.

    Congratulations for your App it seems to be very useful.

    However I have an HTC Desire and i was trying to pair it with the Bluetooth Bee form SeedStudio but it wasn’t posible due to the issue that you reported. Even with your application i’m able to pair it but when i iitiate the serial communication it starts to become buggy.

    Do you have any solution for this?

  7. Niek says:

    Hi,

    Just wanted to let you know that thanks to your amazing app, I can now connect with my HTC Desire (2.2) to the Bluetooth Bee!
    Thanks!

  8. Niek says:

    Hi,

    Just wanted to let you know that thanks to your amazing app, I can now connect with my HTC Desire (2.2) to the Bluetooth Bee!
    Thanks!

  9. Inez says:

    Thanks for this great app! I’ve managed to pair my HTC Desire (2.2) with Seeedstudio’s Bluetooth Bee but can’t get them to connect. Does anyone here have any solutions?

  10. Inez says:

    Thanks for this great app! I’ve managed to pair my HTC Desire (2.2) with Seeedstudio’s Bluetooth Bee but can’t get them to connect. Does anyone here have any solutions?

  11. xxx says:

    I just tried this on a MyTouch 4G, and now I can’t change any of the wireless settings. When I try to open them, I get a dialog saying that the settings process is not responding. And there’s no way to change them now.

  12. xxx says:

    I just tried this on a MyTouch 4G, and now I can’t change any of the wireless settings. When I try to open them, I get a dialog saying that the settings process is not responding. And there’s no way to change them now.

  13. sensation says:

    Seems to crash HTC sensation as well. E.g. settings crash egen accessing bluetooth

    • sensation says:

      Just did a factory reset and tried the app again. It finds the device (seedstudio BT) but fails to properly open the pairing request and then stops responding. But this time it did not mess up the bluetooth settings in the phone.

      It leaves a pairing request on the top bar, but selecting it results in the “settings” app crashing.

      Running the app again does not bring up a new pairing request. It just scans for a while then stalls and reports “there was a problem pairing with the device”

  14. sensation says:

    Seems to crash HTC sensation as well. E.g. settings crash egen accessing bluetooth

    • sensation says:

      Just did a factory reset and tried the app again. It finds the device (seedstudio BT) but fails to properly open the pairing request and then stops responding. But this time it did not mess up the bluetooth settings in the phone.

      It leaves a pairing request on the top bar, but selecting it results in the “settings” app crashing.

      Running the app again does not bring up a new pairing request. It just scans for a while then stalls and reports “there was a problem pairing with the device”

  15. nanoman says:

    After usuing this prog on HTC DHD bluetooth setting always crash when bluetooth activated.

    How fix it without hard reset?

  16. nanoman says:

    After usuing this prog on HTC DHD bluetooth setting always crash when bluetooth activated.

    How fix it without hard reset?

  17. tysm for this … i’m quite a regular user of your blog cus you’ve got some really good content here !

  18. tysm for this … i’m quite a regular user of your blog cus you’ve got some really good content here !

  19. seshadri says:

    Hi,
    I have tried this app on HTC desire HD, OS version2.3.3. This is not detecting nokia BH-106 device. The same device is connecting to other phones. Can you please give me necessary steps?

    I have tried as follows.

    1. Switch on nokia bh-106
    2. Blue tooth on in phone
    3. Make phone discoverable
    4. Tried with this software to detect device (previously I scanned for devices, no results)

    Thanks in advance
    Regards,
    Seshadri

    • seshadri says:

      I found the problem….

      I have reset the settings in the Nokia BH-106, and pressed long time until indicator continuously glow…then scan for devices …

      At last I have paired Bluetooth headset….

  20. seshadri says:

    Hi,
    I have tried this app on HTC desire HD, OS version2.3.3. This is not detecting nokia BH-106 device. The same device is connecting to other phones. Can you please give me necessary steps?

    I have tried as follows.

    1. Switch on nokia bh-106
    2. Blue tooth on in phone
    3. Make phone discoverable
    4. Tried with this software to detect device (previously I scanned for devices, no results)

    Thanks in advance
    Regards,
    Seshadri

    • seshadri says:

      I found the problem….

      I have reset the settings in the Nokia BH-106, and pressed long time until indicator continuously glow…then scan for devices …

      At last I have paired Bluetooth headset….

  21. ThW says:

    Great App!
    Phone: Samsung Galaxy Ace w/ Android 2.3.3
    BT-Device: GNS 5870 GPS-Receiver
    The scan found the GPS at once and paired with it. Thought I have to buy a different receiver that speaks another language than SPP…

  22. ThW says:

    Great App!
    Phone: Samsung Galaxy Ace w/ Android 2.3.3
    BT-Device: GNS 5870 GPS-Receiver
    The scan found the GPS at once and paired with it. Thought I have to buy a different receiver that speaks another language than SPP…

  23. Hecmar says:

    What would have to be done to make a Wiimote work? Its a problem plaguing a large range of phones (Htc, LG, Samsung..) supposedly because in incomplete BT stack, but your explanation is different.. An app allowing the wiimote pairing would be a good idea ($).

  24. Hecmar says:

    What would have to be done to make a Wiimote work? Its a problem plaguing a large range of phones (Htc, LG, Samsung..) supposedly because in incomplete BT stack, but your explanation is different.. An app allowing the wiimote pairing would be a good idea ($).

  25. Rene says:

    Thank you for finding this. I was searching the code piece which suppresses discovering the Bluetooth Bee but since I’m very new to Android development I didn’t found it.

    For all the guys who have crashes:
    This is related to Android < version 2.3 where createRFcommSocketToServiceRecord is buggy.
    see
    http://stackoverflow.com/questions/4444235/problems-connecting-with-bluetooth-android

  26. Rene says:

    Thank you for finding this. I was searching the code piece which suppresses discovering the Bluetooth Bee but since I’m very new to Android development I didn’t found it.

    For all the guys who have crashes:
    This is related to Android < version 2.3 where createRFcommSocketToServiceRecord is buggy.
    see
    http://stackoverflow.com/questions/4444235/problems-connecting-with-bluetooth-android

  27. Tony says:

    Suddenly this software stop detecting COD zero after upgrading my Samsung Galaxy Y to the latest firmware (2.3.6),

    Could you help me on this?

  28. Tony says:

    Suddenly this software stop detecting COD zero after upgrading my Samsung Galaxy Y to the latest firmware (2.3.6),

    Could you help me on this?

  29. Chris says:

    Thank you VERY much, you’ve made my day :) Works fine with SAMSUNG GALAXY ACE, Android 2.3.

    Chris

  30. Chris says:

    Thank you VERY much, you’ve made my day :) Works fine with SAMSUNG GALAXY ACE, Android 2.3.

    Chris

  31. Jacek says:

    Unfortunately, I’ve recently updated my Galaxy Ace from Android 2.3.3 to 2.3.6. Judging from other comments this operation breaks your app. I haven’t tested it however on 2.3.3, because I bought my bluetooth SPP device after this upgrade.

    Nevertheless, currently it isn’t working on Samsung Galaxy Ace. It’s a pity, because app would be _very_ useful!

  32. Jacek says:

    Unfortunately, I’ve recently updated my Galaxy Ace from Android 2.3.3 to 2.3.6. Judging from other comments this operation breaks your app. I haven’t tested it however on 2.3.3, because I bought my bluetooth SPP device after this upgrade.

    Nevertheless, currently it isn’t working on Samsung Galaxy Ace. It’s a pity, because app would be _very_ useful!

  33. Trizza says:

    Hi,

    Thanks for your efforts regarding SPP and Android Phones such as the Galaxy Ace. I’m now facing the same problems. I have bought an OBD2 Bluetooth Adapter (ELM327) which uses SPP, but won’t connect to my 2.3.6 Android Smartphone. I’m afraid your promising app doesn’t work any more. Is there any chance you could release a 2.3.6-compatible version for it anytime soon?

    Regards

    Trizz

  34. Trizza says:

    Hi,

    Thanks for your efforts regarding SPP and Android Phones such as the Galaxy Ace. I’m now facing the same problems. I have bought an OBD2 Bluetooth Adapter (ELM327) which uses SPP, but won’t connect to my 2.3.6 Android Smartphone. I’m afraid your promising app doesn’t work any more. Is there any chance you could release a 2.3.6-compatible version for it anytime soon?

    Regards

    Trizz

  35. Yupp says:

    Is there any solution for android 2.3.6?
    I’ve emailed to samsung support, but they told me to contact the vendor of the spp bluetooth device!!
    The device works properly with other android phones (not using 2.3.6)

  36. Yupp says:

    Is there any solution for android 2.3.6?
    I’ve emailed to samsung support, but they told me to contact the vendor of the spp bluetooth device!!
    The device works properly with other android phones (not using 2.3.6)

  37. Awanish Raj says:

    i have the same problem. i upgraded my samsung galaxy fit to 2.3.6 a while back. now i am doing a project with btbee hc06. my bluetooth scans mobiles but not the spp module. but it is detected in sony xperia mini without any tweak. please help soon. i have a deadline.

  38. Awanish Raj says:

    i have the same problem. i upgraded my samsung galaxy fit to 2.3.6 a while back. now i am doing a project with btbee hc06. my bluetooth scans mobiles but not the spp module. but it is detected in sony xperia mini without any tweak. please help soon. i have a deadline.

  39. GAT says:

    GOOD!! very well, like says Chris: you made my day (and month, and years (JA JA))

    This works in LG-P500h Android 2.2.1

    Thank you

  40. GAT says:

    GOOD!! very well, like says Chris: you made my day (and month, and years (JA JA))

    This works in LG-P500h Android 2.2.1

    Thank you

  41. Don says:

    Thanks for making this and publishing the code. I plan to use the code in an app I am writing to control a class zero BT device so it should come in very useful. What would also be useful is a comprehensive list of all the phones that have been reported to have this problem and those that have been reported to be discoverable using your workaround. Could you start a wiki page that users could edit, giving their phones and whether they are discoverable before and after using your code? That would be wonderful. I will be happy to give you and your site a reference on my page.

  42. Don says:

    Thanks for making this and publishing the code. I plan to use the code in an app I am writing to control a class zero BT device so it should come in very useful. What would also be useful is a comprehensive list of all the phones that have been reported to have this problem and those that have been reported to be discoverable using your workaround. Could you start a wiki page that users could edit, giving their phones and whether they are discoverable before and after using your code? That would be wonderful. I will be happy to give you and your site a reference on my page.

  43. Tnunes says:

    The application seams to solve a common problem to arduino+bt shields developers.
    I have a LG optimus one but i did upgraded the Android version and the application crashes on the discovery phase…is there any workarround?

  44. Tnunes says:

    The application seams to solve a common problem to arduino+bt shields developers.
    I have a LG optimus one but i did upgraded the Android version and the application crashes on the discovery phase…is there any workarround?

  45. joss says:

    Bonjour,

    Avez vous trouver une solution pour galaxy ace en 2.3.6 ?? car mon ELM327 ne fonctionne pas…!!

    SVP aidez moi…..

  46. joss says:

    Bonjour,

    Avez vous trouver une solution pour galaxy ace en 2.3.6 ?? car mon ELM327 ne fonctionne pas…!!

    SVP aidez moi…..

  47. Carl says:

    Hi,

    Any news about fixing it on Galaxy Ace (S5830)? Does anybody know why it doesnt work on this phone?

    • TP says:

      Samsung is responsibile for fixing this problem. The software here is only a workaround. Please contact Samsung.

      As a side note, new Samsung Galaxy Gio (Android version 2.3.6) devices also suffers from the same Bluetooth problem. Older Gio devices (Android version 2.3.3) do not have this problem.

    • Babur says:

      It’s absolutely unknown which Samsung Model supports SPP profile. Also the official internet sites gives wrong information about Bluetooth SPP. I bought 3 different Samsung Model like S5360, S5830i and Galaxy S2. And nothing. Connection attemption released. Some models(S5830i) can pair but not anymore. Not related Android version.

  48. Carl says:

    Hi,

    Any news about fixing it on Galaxy Ace (S5830)? Does anybody know why it doesnt work on this phone?

    • TP says:

      Samsung is responsibile for fixing this problem. The software here is only a workaround. Please contact Samsung.

      As a side note, new Samsung Galaxy Gio (Android version 2.3.6) devices also suffers from the same Bluetooth problem. Older Gio devices (Android version 2.3.3) do not have this problem.

    • Babur says:

      It’s absolutely unknown which Samsung Model supports SPP profile. Also the official internet sites gives wrong information about Bluetooth SPP. I bought 3 different Samsung Model like S5360, S5830i and Galaxy S2. And nothing. Connection attemption released. Some models(S5830i) can pair but not anymore. Not related Android version.

  49. Sajid says:

    hi,
    google play and other sites for iran in forbidden, how can in download this app directly?

  50. Sajid says:

    hi,
    google play and other sites for iran in forbidden, how can in download this app directly?

  51. Nauman Mufti says:

    Hi,

    I am really new to Android and the ADB, etc. I tried your app and it doesn’t work on my Android Samsung Galaxy Q (2.3.6) phone. Is there some other way for me to make the modifications you showed on my phone (perhaps using android development board).
    Any advise would be highly appeciated.

    Thanks so much,
    Kind regards,
    Nooman Mufti

  52. Nauman Mufti says:

    Hi,

    I am really new to Android and the ADB, etc. I tried your app and it doesn’t work on my Android Samsung Galaxy Q (2.3.6) phone. Is there some other way for me to make the modifications you showed on my phone (perhaps using android development board).
    Any advise would be highly appeciated.

    Thanks so much,
    Kind regards,
    Nooman Mufti

  53. Nauman Mufti says:

    Hi,

    Faced with the same problem. I am trying to connect my Android 2.3.6 (Samsung Galaxy Q) to a JY-MCU (the same as the Bee but the basic chip only). This app didn’t work so I tried the BluePair app which I bought!. It allows me to manually enter the MAC address of the device and I can pair to it.
    The problem is that the Amarino software I am using to communicate with my Arduino tries to again ‘scan’ for the bluetooth device and doesn’t see the already paired device. In contrast the Bluetooth API of the phone sees the paired device. Is there some way to force the other softwares to see the existing added device ?

    Or is there some way for me to use the Java class you uploaded. I am close to 0 experience working on Android Dev Kit but can follow any instructions you might be kind enough to give.

    Thanks so much,
    Kind regards,
    Nooman

  54. Nauman Mufti says:

    Hi,

    Faced with the same problem. I am trying to connect my Android 2.3.6 (Samsung Galaxy Q) to a JY-MCU (the same as the Bee but the basic chip only). This app didn’t work so I tried the BluePair app which I bought!. It allows me to manually enter the MAC address of the device and I can pair to it.
    The problem is that the Amarino software I am using to communicate with my Arduino tries to again ‘scan’ for the bluetooth device and doesn’t see the already paired device. In contrast the Bluetooth API of the phone sees the paired device. Is there some way to force the other softwares to see the existing added device ?

    Or is there some way for me to use the Java class you uploaded. I am close to 0 experience working on Android Dev Kit but can follow any instructions you might be kind enough to give.

    Thanks so much,
    Kind regards,
    Nooman

  55. Tim Mudford says:

    Any chance you could get this to work with the Galaxy Gio (Android 2.3.6 version)?

    • André says:

      I have found a way.

      Use SENA BTerm program to connect to your device. Under Bluetooth Management, enter the Device number, click Select and Connect. Enter the password (usualy 1234). Now the device is included in the bluetooth devices list.

      The trick here is to find the Device number. I my case, I have used an other cellphone running android 2.3.3 witch was able to detect the module. The number appears in the device list like 20:13:05:06:47:16. Use this number without the “:” 201305064716

      Good luck!

  56. Tim Mudford says:

    Any chance you could get this to work with the Galaxy Gio (Android 2.3.6 version)?

  57. daniel says:

    Hi,

    Thank you for this solution. I have used it in my code and it works but I have a question. For my purpose is not good to make a connection (pairing dialog is shown) and disconnect. I tried it without a connection but I got device name as null.

    Can you tell me why I get device name null without making a connection? When I start discovery I got device name without making a conection in broadcast receiver so it means that making a connection is not necessary to get device name. Thank you.

  58. daniel says:

    Hi,

    Thank you for this solution. I have used it in my code and it works but I have a question. For my purpose is not good to make a connection (pairing dialog is shown) and disconnect. I tried it without a connection but I got device name as null.

    Can you tell me why I get device name null without making a connection? When I start discovery I got device name without making a conection in broadcast receiver so it means that making a connection is not necessary to get device name. Thank you.

  59. Michael Sternberg says:

    Does anyone know how to pair a Vizio headset with a Jabra Bluetooth adaption for an IPOD Micro please?

  60. I know this if off topic but I’m looking into starting my own blog
    and was curious what all is needed to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very internet savvy so I’m not 100% positive.
    Any recommendations or advice would be greatly appreciated.

    Kudos

  1. There are no trackbacks for this post yet.