我尝试配对两台设备如何使用NFC
一个是谷歌Nexus S的具有广告应用程式运行的读取写入了该卡在其他手机上的标签上的MAC地址这不是Android的一个。
现在我试图配对设备,因为我点击其他手机时,我的应用程序将读取存储在TAG中的MAC地址并自动创建蓝牙连接。
一切工作正常,但我得到一个配对请求或匹配两个手机上的键不应该来。
这里是蓝牙细分市场,在连接发生
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);
}
}
}
我想对不安全的连接,但我不知道为什么它被要求同时在手机的配对键。
你好,我需要开发相同的功能。请告诉我如何在设备靠近时配对并开始传输NDEF消息。请回复我。它的紧急请。 – 2012-04-20 15:57:23