Question

I'm trying the following:

sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
    goto gotError;
}

lastlen = 0;
len = 100 * sizeof(struct ifreq);   /* initial buffer size guess */
for ( ; ; ) {
    buf = (char*)malloc(len);
    if (buf == NULL) {
        goto gotError;
    }
    ifc.ifc_len = len;
    ifc.ifc_buf = buf;
    if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {

However, ioctl only returns interfaces for the loopback and wifi:

(gdb) p ifc.ifc_ifcu.ifcu_req[0].ifr_ifrn.ifrn_name
$1 = "lo", '\000' <repeats 13 times>
(gdb) p ifc.ifc_ifcu.ifcu_req[1].ifr_ifrn.ifrn_name
$2 = "wlan0\000\000\000\000\000\000\000\000\000\000"
(gdb) p ifc.ifc_ifcu.ifcu_req[2].ifr_ifrn.ifrn_name
$3 = "\344\233\025j\000\000\000\000m\004\357k\005\000\000"

In the manifest, there is:

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

Is it possible to get bluetooth discovery to work with the NDK or do I need to resort to Java?

Was it helpful?

Solution

As far as I can tell, it's not possible. I resorted to using this Java sample as a template and building a native bridge to it.

I adapted and extended Demo_Multiscreen.java to a BluetoothConnectionManager class and did all the bridging from and to that.

The extended Java source is available in the google directory of this github repo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top