This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Android NDK Support?

I need to write some code at the NDK level to access some Bluetooth features that aren't exposed at the Java level. For example, I want to have a 2nd bluetooth adapter on my Android device. I looked at the SDK download and the Github Android samples and there isn't anything obvious there to help. Is there any C code or SDK/API docs that can be used? I looked at getting the card and SDK from a supplier but they didn't know if there would be any Android driver support either, and suggested that I come here for guidance. Any ideas would be appreciated. Right now, I just building my application using generic code that accesses the bluedroid headers in the NDK, and it's very painful! Thanks.

  • Yes. That's my goal. I want to have two physically separate bluetooth antennas. One is on-board, and the second bluetooth antenna is connected via powered USB cable at a distance of about 10m. I am currently trying to use the userial_init, userial_open and userial_read low level bluedroid calls, but I'm running up against hurdles. I was thinking that maybe the Nordic SDK might be better than the bluedroid one (it can hardly be any worse). At least the Nordic SDK is very well documented.

  • I see. I cannot help you with the current approach, but i can suggest different ones

    1. Use a small linux computer instead (like a raspberry pi), with 2 usb dongles.
    2. Use two phones, and make them report to each other over wifi
    3. Create two BLE scanners, which report scan results to one phone over BLE
  • Thanks for the suggestions. I had suggested #1 before, and that's not a cost effective solution for my situation. Looking at the Android Blueooth (Bluedroid) internals, I think it should be possible, but pretty hard. But, the Bluedroid stuff is some poorly documented, and buggy, it's a daunting task. I have the nRF51-Dongle, and it's at least recognized by my Android device when I plug it in. I bet that you could get it working with your SDK as a research project. But, I guess I will keep hacking away at the Bluedroid.

  • You have two issues here that involve a bit of misunderstanding. One is, BLE central and BLE peripheral both use the same mechanism to ping for RSSI. If you blindly and naively attempt RSSI triangulation, you absolutely can do it with one BLE device in your Android hardware and several peripheral devices used for triangulation all simultaneously connected to the one BLE device on the Android hardware. Your embedded nordic chip BLE can only handle one connection at a time, this is not a limitation of the expensive dual WiFi/BLE chips. 3 to 5 device connections should be fine. CSR BLE 101x allows you to broadcast / scan even while already being connected, which allows all your peripherals to be able to ping each other for RSSI while being connected to the Android device and not to each other, which is another reason why you don't need multiple BLE adapters in one Android device. I assume Nordic BLE chip also lets you do this.

    Second issue is you can thunk into Java from C++, it goes both ways, not a big deal. Use the REGULAR Android BLE Java library in your C++ application, thunk into it. There is no BLE API in the NDK and whatever you think you can use in lieu of it will be laughable at best. I have successfully used the Android BLE Java library from C++ in my app. It is a pain but better than the alternative.

  • Thanks for taking the time to answer, but I'm not writing any Java code. But, given the lack of support here for Android, I gave up on using the Nordic Product. I directly ported the Bluez library code, and it works fine on our Cambridge USB dongles. Our code works fine with the onboard bluetooth and the USB connected dongle now.

Related