Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: getBluetoothService() called with no BluetoothManagerCallback

I'm trying to connect my Nexus 4 with a Wii Balance Board but I get this error:

getBluetoothService() called with no BluetoothManagerCallback
connect(), SocketState: INIT, mPfd: null

So it doesn't finish the connection.

My socket:

public final class wSocket
{
    public static BluetoothSocket create(BluetoothDevice dev, int port)
    {
        try {
        /*
         * BluetoothSocket(int type, int fd, boolean auth, boolean encrypt, BluetoothDevice device, int port, ParcelUuid uuid)
         */
            Constructor<BluetoothSocket> construct = BluetoothSocket.class.getDeclaredConstructor(int.class, int.class, boolean.class,
                boolean.class, BluetoothDevice.class, int.class, ParcelUuid.class);

            construct.setAccessible(true);
            return construct.newInstance(3 /* TYPE_L2CAP */, -1, false, false, dev, port, null);
        } catch (Exception ex) {
            return null;
        }
    }
}

Where it gives me the error:

private BluetoothSocket sk;
...
sk = wSocket.create(wm.dev, 0x11);
...
sk.connect();

I have checked this link with no success because I just open 1 socket: getbluetoothservice() called with no bluetoothmanagercallback

Any help or idea to explore?

like image 834
omniyo Avatar asked Jun 25 '13 18:06

omniyo


1 Answers

Try to get BluetoothAdapter via getDefaultAdapter() prior to socket object create. It seems that callback service is created when reference to BLuetoothAdater is taken by above mentioned call. For details : https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothAdapter.java

where mService = managerService.registerAdapter(mManagerCallback); is loaded with value when getDefaultAdapter is called.

for socket connect() the getBluetoothService() argument is always null, see code below:

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothSocket.java

p.s. it seems that google does not advertise usage of BluetoothSocket constructor directly and asking to use method of BluetoothDevice to get socket created.(from reference on google site) the reason behind is not known to me.

like image 169
Asaf Sh. Avatar answered Nov 10 '22 16:11

Asaf Sh.