8

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?

Community
  • 1
  • 1
omniyo
  • 330
  • 2
  • 6
  • 19
  • What version of android are you using? I am also getting this error now all of a sudden, but never had it before. – T.Coutlakis Nov 23 '13 at 16:40
  • I just started seeing this error on Android 4.4. I've done a lot of work with Bluetooth on a wide variety of devices, though mostly 2.x and 3.x. – Brodo Fraggins Jun 30 '14 at 21:57

1 Answers1

1

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.

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
Asaf Sh.
  • 49
  • 2
  • I forgot to say that I call "_adapter = BluetoothAdapter.getDefaultAdapter();" before the socket object creation. – omniyo Jun 26 '13 at 18:36
  • did you try to create socket using BluetoothDevice or you wish to achieve better control (port channel etc) via implicit BluetoothSocket constructor? And on what Android product revisions did you test you code? – Asaf Sh. Jun 27 '13 at 00:26
  • 3
    Just for anyone using an IOIO device (provides various external interface pins for smartphones to access outside signals) who happens on this thread: I started getting this error out of the blue during an app development and it wouldn't go away even with a restart of my Android smartphone. The error disappeared when I power-cycled (powered off then back on) the IOIO board. – John Jorsett Mar 26 '14 at 00:29