我在这里下载了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) 我真的很困惑。
答案 0 :(得分:3)
createInsecureRfcommSocketToServiceRecord()
有
"不安全"设备用于通信的密钥,即蓝牙2.1以下,未加密。这就是"不安全"。
但它没有改变这样一个事实:如果MAC地址不在配对数据库中,那么总会有提示。
是的,它会提示。