我在这里下载了 BluetoothChat 示例项目: https ://android.googlesource.com/platform/development/+/master/samples/BluetoothChat?autodive=0%2F
事实是,当我在两个设备(未配对)上启动应用程序时,它应该连接两个设备而不要求配对两个设备,不是吗?事实上,当我尝试连接两个设备(未配对)时,它要求配对设备。我的意思是,BluetoothChatService.java 中有这个函数应该创建一个不安全的套接字。但似乎,它不做他的工作?
/**
* This thread runs while attempting to make an outgoing connection
* with a device. It runs straight through; the connection either
* succeeds or fails.
*/
private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
private String mSocketType;
public ConnectThread(BluetoothDevice device, boolean secure) {
mmDevice = device;
BluetoothSocket tmp = null;
mSocketType = secure ? "Secure" : "Insecure";
// Get a BluetoothSocket for a connection with the
// given BluetoothDevice
try {
if (secure) {
tmp = device.createRfcommSocketToServiceRecord(
MY_UUID_SECURE);
} else {
tmp = device.createInsecureRfcommSocketToServiceRecord(
MY_UUID_INSECURE);
}
} catch (IOException e) {
Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
}
mmSocket = tmp;
}
有人可以解释一下为什么它要求将两个设备配对吗?createInsecureRfcommSocketToServiceRecord 方法不应该要求配对未配对的设备,不是吗?x) 我真的很困惑。