如果我理解正确,你有一个MAC地址作为一个字符串,你想连接到设备,对吗?这应该工作:
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
BluetoothSocket tmp = null;
BluetoothSocket mmSocket = null;
// Get a BluetoothSocket for a connection with the
// given BluetoothDevice
try {
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);
} catch (IOException e) {
Log.e(TAG, "create() failed", e);
}
mmSocket = tmp;
该应用程序是用于调试蓝牙连接和原始协议数据的简单工具. (现在只有在ascii中,我打算添加功能来调试十六进制.)