saa*_*i63 9 android bluetooth nfc
我是Android世界的完全新手.如果我的问题太天真,请原谅我.
我一直在研究一个示例应用程序,以实现Linux Box(运行Bluez-5.42的FC-21)和Android平板电脑之间的蓝牙配对.我正在使用NFC将蓝牙名称,地址和OOB数据从PC传输到Android.我能够通过NFC将这些数据从PC发送到Android(精确的光束),我能够解析和解码Android端的所有数据.借助Android上可用的Linux机箱的蓝牙地址,我可以调用CreateBond()将Android平板电脑与Linux Box配对.我测试了这部分,它按预期工作.
现在,这种方法的问题在于,在蓝牙配对期间使用数字比较或密码输入关联模型,当我使用NFC进行配对时,我觉得这是用户体验的偏差.由于我已经拥有了PC的OOB数据,因此我想使用OOB关联进行配对,这样就不会损害用户体验.
为此,当我用CreateBondOutOfBand()[使用反射]替换CreateBond()时,没有从Android向Linux PC发送配对请求.
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.");
}
Run Code Online (Sandbox Code Playgroud)
我在网上搜索但找不到任何具体证据表明可以在Android中实现OOB配对.
此外,为了检查原生Android的行为,我创建了一个NFC标签,其中包含Linux机器的蓝牙名称,地址和OOB数据.当我对Android平板电脑持有标签时,Bluettoth配对已启动但仍未使用OOB关联模型.
我的问题如下,
任何投入将不胜感激.
谢谢,
西
我不使用 NFC,但我使用反射来使用 createBondOutOfBand。另外,此代码确实适用于 Motorola lineage rom 7.1(在 Moto G4 play 和 Moto E 2015 上)和 Samsung 官方 rom 7.0(Galaxy S6),但不适用于 LG G5 或 G6 官方 rom 7.0(身份验证总是失败) )。
这是我的代码(与你的@saai63 并没有太大不同)。
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1898 次 |
| 最近记录: |