谷歌眼镜上的rfcomm蓝牙

时间:2013-12-23 22:11:39

标签: android google-glass android-bluetooth google-gdk

我有一个Android-App [1],我部分想要移植到谷歌眼镜 - 这个应用程序使用蓝牙rfcomm。现在我面临以下问题:当我使用我的连接代码时,我在玻璃上看到一个配对对话框 - 向我显示一个大数字并要求点击确认。但这很奇怪 - 因为我通常不得不在手机上输入我的4位数字引脚 - 我也遇到了验证问题(闻起来像是因为我不让我输入PIN码) 谁在谷歌眼镜上使用bluetooth-rfcomm?

[1] https://github.com/ligi/DUBwise

1 个答案:

答案 0 :(得分:1)

我遇到了这样的确切问题!在这个post中,我完全解决了这个问题。

但基本上配对是这样完成的:

在BroadcastReceiver中

    if(BluetoothDevice.ACTION_PAIRING_REQUEST.equals(action)){
        BluetoothDevice device = ListDev.get(selectedDevice);
        byte[] pinBytes = getStrFromName(device.getName(),7,11).getBytes();  // My devices had their own pin in their name, you can put a constant pin here or ask for one...  
        try {
            Method m = device.getClass().getMethod("setPin", byte[].class);
            m.invoke(device, pinBytes);
            try {
                device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
            } catch (Exception e) {
                e.printStackTrace();
            } 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

因此,在此示例中,引脚会自动设置,但您始终可以向用户请求引脚。

希望它有所帮助!

相关问题