首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android真的支持蓝牙OOB配对吗?

Android真的支持蓝牙OOB配对吗?
EN

Stack Overflow用户
提问于 2017-01-12 08:57:35
回答 1查看 3.2K关注 0票数 9

我完全是Android.Please世界的新手,如果我的问题太天真,请原谅。

我一直在开发一个示例应用程序,以实现Linux Box (运行Bluez-5.42的FC-21)和Android平板电脑之间的蓝牙配对。我正在使用NFC将蓝牙名称、地址和OOB数据从PC传输到Android。我能够通过NFC (准确地说是beam)将上述数据从PC发送到Android,并且我能够在Android端解析和解码所有数据。根据安卓提供的Linux Box的蓝牙地址,我可以调用CreateBond()将Android平板电脑与Linux box配对。我已经测试了这部分,它可以像预期的那样工作。

现在,这种方法的问题是,在蓝牙配对期间,使用了数字比较或密钥输入关联模型,我认为这是对用户使用NFC进行配对时体验的一种偏差。因为我已经有了PC的OOB数据,所以我想使用OOB关联进行配对,这样用户体验就不会受到影响。

为此,当我使用反射将CreateBond()替换为CreateBondOutOfBand()时,没有任何配对请求从Android发送到Linux PC。

代码语言:javascript
复制
       try {
        showLog("Pairing started");
        Method m = bDev.getClass().getMethod("createBondOutOfBand", byte[].class, byte[].class);
        showLog("Found method");
        Boolean flag = (Boolean) m.invoke(bDev, Hash, Rand,(Object[]) null);
        //Method m = bDev.getClass().getMethod("createBond", (Class[]) null);
        //Boolean flag = (Boolean) m.invoke(bDev, (Object[]) null);
        if(flag)
            showLog("Pairing successfully finished.");
        else
            showLog("Pairing failed");
    } catch (Exception e) {
        showLog("Pairing failed.");
    }

我在网上搜索,但没有找到任何确凿的证据表明OOB配对可以在Android中实现。

此外,为了检查原生Android的行为,我创建了一个带有蓝牙名称、地址和Linux机器的OOB数据的NFC标签。当我将标签放在Android平板电脑上时,Bluettoth配对开始了,但它仍然没有使用OOB关联模型。

我的问题如下:

  • Android真的支持OOB关联模型吗?
  • 如果支持OOB关联模型,是否使用CreateBondOutOfBand()接口,或者是否有其他接口需要使用?

我们将非常感谢您的任何投入。

谢谢,

赛斯

EN

回答 1

Stack Overflow用户

发布于 2017-10-11 16:22:27

我不使用近场通信,但我使用反射来使用createBondOutOfBand。此外,此代码可以在摩托罗拉血统rom7.1(在Moto G4 play和Moto e 2015上)和三星官方rom 7.0 (Galaxy S6)上工作,但不能在LG G5或G6官方rom 7.0上工作(认证总是失败)。

这是我的代码(与你的@saai63没有什么不同)。

代码语言:javascript
复制
private boolean createBondOutOfBand(final byte[] oobKey) {
    try {
        if (DEBUG) {
            Log.d(LOG_TAG, "createBondOutOfBand entry");
        }

        Class c = Class.forName("android.bluetooth.OobData");
        Constructor constr = c.getConstructor();
        Object oobData = constr.newInstance();
        Method method = c.getMethod("setSecurityManagerTk", byte[].class);
        method.invoke(oobData, oobKey);

        Method m = mBluetoothDevice.getClass().getMethod("createBondOutOfBand", int.class, c);
        boolean res = (boolean)m.invoke(mBluetoothDevice, BluetoothDevice.TRANSPORT_AUTO, oobData);

        if (DEBUG) {
            Log.d(LOG_TAG, "createBondOutOfBand result => " + res);
        }

        return res;

    }
    catch (Exception e) {
        Log.e(LOG_TAG, "Error when calling createBondOutOfBand", e);
        return false;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41603450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档