我的代码:
private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device){
BluetoothSocket tmp = null;
mmDevice = device;
try{
tmp = device.createInsecureRfcommSocketToServiceRecord("myID",d364b420-8d71-11e3-baa8-0800200c9a66);
} catch (IOException e){}
mmSocket = tmp;
}
}
我研究了UUID的Here并且它想要一个名字和UUID,但我得到一个错误,说明TypeBodeDevice不适用于参数(在论证中使用了UUID,或者它会说我提供的UUID无法解析为变量。我认为我需要一个名称和一个uuid用于函数createInsecureRfcommSocketToServiceRecord的参数吗?任何帮助都会很棒!
答案 0 :(得分:1)
这是无效的语法:
tmp = device.createInsecureRfcommSocketToServiceRecord("myID",d364b420-8d71-11e3-baa8-0800200c9a66);
首先,根据API documentation,该方法只需要一个参数,而UUID
就是UUID
。
当然,你不能像你一样把UUID放在那里。它必须是UUID uuid = UUID.fromString("d364b420-8d71-11e3-baa8-0800200c9a66");
tmp = device.createInsecureRfcommSocketToServiceRecord(uuid);
对象。尝试这样的事情:
{{1}}