Bluetooth 如何使用NFC在两个设备中配对蓝牙
我正在尝试配对两个设备 一个是Google Nexus S,它运行应用程序读取标签上写的mac地址,标签贴在另一个不是Android One的手机上 现在,当我点击另一部手机时,我尝试将设备配对,我的应用程序读取标签中存储的MAC地址,并自动创建蓝牙连接 一切正常,但我收到一个配对请求或匹配两部手机上的钥匙,但不应该出现 这是正在进行连接的蓝牙段Bluetooth 如何使用NFC在两个设备中配对蓝牙,bluetooth,nfc,Bluetooth,Nfc,我正在尝试配对两个设备 一个是Google Nexus S,它运行应用程序读取标签上写的mac地址,标签贴在另一个不是Android One的手机上 现在,当我点击另一部手机时,我尝试将设备配对,我的应用程序读取标签中存储的MAC地址,并自动创建蓝牙连接 一切正常,但我收到一个配对请求或匹配两部手机上的钥匙,但不应该出现 这是正在进行连接的蓝牙段 private class ConnectThread extends Thread { private final BluetoothSoc
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);
Log.d("CHECK", "Sucessfully created insecure socket");
}
} catch (IOException e) {
Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
}
mmSocket = tmp;
}
public void run() {
Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType);
setName("ConnectThread" + mSocketType);
// Always cancel discovery because it will slow down a connection
mAdapter.cancelDiscovery();
Log.d("CHECK", "Inside RUN");
// Make a connection to the BluetoothSocket
try {
// This is a blocking call and will only return on a
// successful connection or an exception
Log.d("CHECK", "Trying to connect");
mmSocket.connect();
Log.d("CHECK", "Tried to connect");
} catch (IOException e) {
// Close the socket
try {
mmSocket.close();
Log.d("CHECK", "Socket closed");
} catch (IOException e2) {
Log.e(TAG, "unable to close() " + mSocketType +
" socket during connection failure", e2);
}
Log.d("CHECK", "Connection failed");
connectionFailed();
return;
}
// Reset the ConnectThread because we're done
synchronized (BluetoothChatService.this) {
mConnectThread = null;
}
// Start the connected thread
connected(mmSocket, mmDevice, mSocketType);
Log.d("CHECK RESULT", "Sucessfully connected");
// Toast.makeText(BluetoothChatService.ConnectThread.this, "Sucessfully connected" , Toast.LENGTH_LONG).show();
}
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) {
Log.e(TAG, "close() of connect " + mSocketType + " socket failed", e);
}
}
}
我正在尝试不安全的连接,但我不知道为什么它会要求两部手机都有配对键。检查您的蓝牙版本,因为:
(sic)“对于Bluetooth 2.1设备,链接密钥将被加密,因为加密是必需的。对于旧式设备(蓝牙2.1之前的设备),链接密钥将不会被加密。”感谢您的回复。。但是我正在使用命令tmp=device.createUnsecurerCommsockettoServiceRecord(我的UUID不安全);该命令的解释说,它将继续并使连接绕过所需的加密链接。你确定吗?我的答案是从网上文档的解释中抄来的。请再次检查。您好,我需要开发相同的功能。请告诉我当设备靠近并开始传输NDEF消息时,您如何配对设备。请回答我。有急事。