4
나는 블루투스 프로젝트를하고 있는데, 블루투스를 사용하여 두 장치를 연결하려고합니다.블루투스를 사용하여 두 개의 안드로이드 장치를 프로그래밍 방식으로 연결하십시오.
tf developer.android.com의 지침 및 코드를 따르고 있습니다.이 문제를 해결하는 데 도움이 될 수 있습니까? 여기에 제가 시도한 코드가 있습니다.
누구나 생성자가 장치 개체를 수신하는 위치를 알 수 있습니까?
private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
<!-- can anyone tell me from where device object comes here --!>
public ConnectThread(BluetoothDevice device) {
// Use a temporary object that is later assigned to mmSocket,
// because mmSocket is final
BluetoothSocket tmp = null;
mmDevice = device;
// Get a BluetoothSocket to connect with the given BluetoothDevice
try {
// MY_UUID is the app's UUID string, also used by the server code
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) { }
mmSocket = tmp;
}
public void run() {
// Cancel discovery because it will slow down the connection
mBluetoothAdapter.cancelDiscovery();
try {
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
mmSocket.connect();
} catch (IOException connectException) {
// Unable to connect; close the socket and get out
try {
mmSocket.close();
} catch (IOException closeException) { }
return;
}
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(mmSocket);
}
/** Will cancel an in-progress connection, and close the socket */
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) { }
}
}
Thanks inadvance
연구를 완료 했습니까? [http://developer.android.com/guide/topics/wireless/bluetooth.html] (안드로이드 Blutooth) – cstrutton
숙제를하십시오 질문하기 전에 철저히 대답을 검색 했습니까? 귀하의 연구를 공유하는 것은 모든 사람들을 돕습니다. 귀하가 발견 한 내용과 귀하의 필요를 충족시키지 못한 이유를 저희에게 알려주십시오. 이것은 시간을내어 자신을 도우려는 것을 보여 주며, 명백한 답을 되풀이하지 않아도되며, 무엇보다도보다 구체적이고 관련성있는 답변을 얻는 데 도움이됩니다! 사람들이 왜 투표를하는 지 확신 할 수 없습니까? – cstrutton