android 6+ How to connect wii balance board?

5.1k views Asked by At

I made an Android app that connected and readed input fine with Wii balance board, based on Fitscales code. My app worked like a charm with SDK 15 & 16 until Android 4.4 (KitKat), when Android stopped the Wii support. Wii support is now re-enabled, starting with Android 5.1.1. I have also implemented the new permission scheme for obtaining Bluetooth connectivity permissions (inlcuded ACCESS_COARSE_LOCATION)

My problem is that I can't read Wii balance board input anymore.

I can discover, create socket and when connecting to socket I receive the message: read failed, socket might closed or timeout, read ret: -1

Answer that helped me so far and not working anymore:

Create wiimote socket

How to connect

Some code:

private BluetoothSocket createBluetoothSocket(
        int type, int fd, boolean auth, boolean encrypt, String address, int port){
    try {
        Constructor<BluetoothSocket> constructor = BluetoothSocket.class.getDeclaredConstructor(
                int.class, int.class,boolean.class,boolean.class,String.class, int.class);
        constructor.setAccessible(true);
        BluetoothSocket clientSocket = constructor.newInstance(type,fd,auth,encrypt,address,port);
        return clientSocket;
    } catch (Exception e) {
        Log.v(TAG,"createBluetoothSocket failed: "+errorMsg(e));
        return null;
    }
}   


private connectWii(String MAC) {
    try {
        // MAC is the MAC address of Wiiboard
        int TYPE_L2CAP=3;
        sk = createBluetoothSocket(TYPE_L2CAP, -1, false,false, MAC, 0x13);
        // this fires read failed, socket might closed or timeout, read ret: -1
        sk.connect();
    } catch (Exception e) {
        Log.v(TAG,"Failed : "+errorMsg(e));
    }
}

Thank for your help in advance.

1

There are 1 answers

0
Garbit On BEST ANSWER

It's worth looking at the responses in this question - https://android.stackexchange.com/a/105285

It would appear that Android 4.1 and below provides access to the L2CAP protocol to connect to Bluetooth classic devices (circa 2005 and older) which has been removed from more recent builds of Android.