gpt4 book ai didi

android - device.createInsecureRfcommSocketToServiceRecord 无法正常工作

转载 作者:行者123 更新时间:2023-11-29 17:42:39 25 4
gpt4 key购买 nike

我在这里下载了 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() 有“不安全”设备用于通信的 key ,即低于蓝牙 2.1,未加密。这就是“不安全”。

但这并没有改变这样一个事实,即如果 MAC 地址不在配对数据库中,则始终会有提示。

是的,它会提示。

关于android - device.createInsecureRfcommSocketToServiceRecord 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28029867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com