안드로이드 장치에서 내 장치와 원격 장치 (쌍으로 연결)를 연결하고 싶습니다. 원격 장치는 HC-05 모듈입니다. 내 대구는 다음과 같습니다 :안드로이드 블루투스가 원격 장치에 연결
private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
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 = mmDevice.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
}
mmSocket = tmp;
}
@Override
public void run() {
// Cancel discovery because it will slow down the connection
ba.cancelDiscovery();
try {
mmSocket.connect();
} catch (IOException e) {}
// Do work to manage the connection (in a separate thread)
// manageConnectedSocket(mmSocket);
// connected();
tv1.setText("connect");
}
/** Will cancel an in-progress connection, and close the socket */
@SuppressWarnings("unused")
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) {
}
}
}
줄에 mSocket.connect() 오류가 나타납니다. 내 앱을 실행 한 다음 메시지가 표시됩니다. 불행히도 (앱 이름)이 중지되었습니다.
도와주세요.
LogCat에서 오류 메시지와 예외를 살펴 보셨습니까? 이 코드에서는 –
이 아니지만 비슷한 코드에서 오류가 발생합니다. 읽기 실패 소켓이 닫혔거나 시간 초과되었습니다. 읽기 – user3223395