开发者社区> 问答> 正文

关于Android 蓝牙ble配对 发送PIN码无效问题

在做蓝牙配对时,发现调用setPin函数发送PIN码,如123456时,蓝牙设备那边一直显示PIN错误。
我试过了无论是字符串的123456,还是数字123456都不行,但是使用全0的PIN可以配对成功,请大神指教。。

 byte[] pin = (byte[]) BluetoothDevice.class.getMethod("convertPinToBytes", String.class).invoke(BluetoothDevice.class, "123456");
  Log.i("pair", Arrays.toString(pin));
  boolean flag = device.setPin(pin);

展开
收起
爵霸 2016-03-12 11:46:15 5262 0
1 条回答
写回答
取消 提交回答
  • private static final Method _setPin = getMethod(BluetoothDevice.class, "setPin", new Class[] { byte[].class });
     public boolean setPin(byte[] pin) throws Exception {
     if (_setPin == null)
     throw new NoSuchMethodException("setPin");
        try {
            return (Boolean)_setPin.invoke(mDevice, pin);
        } catch (InvocationTargetException tex) {
            if (tex.getCause() instanceof Exception)
                throw (Exception)tex.getCause();
            else
                throw tex;
        }
    }
    
    2019-07-17 19:00:37
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载