我嘗試配對兩臺設備如何使用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