device.createInsecureRfcommSocketToServiceRecord 无法正常工作
device.createInsecureRfcommSocketToServiceRecord doesn't work properly
我在这里下载了 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)
我真的很困惑。
createInsecureRfcommSocketToServiceRecord()
有的
"insecure" 设备用于通信的密钥,低于蓝牙 2.1,未加密。那就是"unsecure".
但这并没有改变这样一个事实,即如果 MAC 地址不在配对数据库中,那么总会有提示。
所以是的,它会提示。
我在这里下载了 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) 我真的很困惑。
createInsecureRfcommSocketToServiceRecord()
有的
"insecure" 设备用于通信的密钥,低于蓝牙 2.1,未加密。那就是"unsecure".
但这并没有改变这样一个事实,即如果 MAC 地址不在配对数据库中,那么总会有提示。
所以是的,它会提示。