安卓:getBluetoothService()调用时没有BluetoothManagerCallback [英] Android: getBluetoothService() called with no BluetoothManagerCallback

查看:15498
本文介绍了安卓:getBluetoothService()调用时没有BluetoothManagerCallback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接我的Nexus 4采用了Wii的平衡板,但我得到这个错误:

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.

我的插座:

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();

我已经检查不出来这个环节,因为我只开1插槽: <一href="http://stackoverflow.com/questions/15889908/getbluetoothservice-called-with-no-bluetoothmanagercallback">getbluetoothservice()所谓无bluetoothmanagercallback

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?

在此先感谢。

推荐答案

尝试通过getDefaultAdapter得到BluetoothAdapter(),以Socket对象创建之前。看来,当采取的是上述的呼叫参考BLuetoothAdater回调服务被创建。有关详情: <一href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothAdapter.java" rel="nofollow">https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothAdapter.java

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

在这里MSERVICE = managerService.registerAdapter(mManagerCallback);装入时getDefaultAdapter调用值

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

套接字连接()的getBluetoothService()参数总是空,见下文code:

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

<一个href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothSocket.java" rel="nofollow">https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothSocket.java

P.S。看来,谷歌并不直接发布的BluetoothSocket构造函数的用法,并要求使用BluetoothDevice类的方法来获取套接字创建。(从谷歌网站参考)背后的原因是不知道在我身上。

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.

这篇关于安卓:getBluetoothService()调用时没有BluetoothManagerCallback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆