Android蓝牙连接蓝牙rs232适配器

时间:2014-07-15 10:58:01

标签: android bluetooth android-bluetooth

我一直在计划制作一款能与这款蓝牙rs232适配器通讯的Android应用程序

http://www.nordfield.com/wireless-serial-rs232-bluetooth-adapter

我不知道在这种情况下我应该怎么处理UUID?我是否可以开始与应用程序建立连接,这看起来像是来自Google的BluetoothChat示例应用程序?

https://android.googlesource.com/platform/development/+/25b6aed7b2e01ce7bdc0dfa1a79eaf009ad178fe/samples/BluetoothChat/

1 个答案:

答案 0 :(得分:1)

嗯,我已经解决了这个问题。实际上,有可能在不知道设备的UUID的情况下创建蓝牙连接。它是通过以下代码实现的:

public ConnectThread(BluetoothDevice device) {
        mmDevice = device;
        BluetoothSocket tmp = null;

        try {               
            Method method;

            method = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class } );
            tmp = (BluetoothSocket) method.invoke(device, 1);  

        } catch (Exception e) { }

        mmSocket = tmp;
    }    

所有其余的连接管理都与Google的BluetoothChat示例应用程序完全相同。