안녕하세요.
블루투스 connect() 부분에서 계속 연결이 안되서 질문 드려봅니다.
블루투스 대상 장비는 전저펜이구요, 블루투스 장비와는 페어링되어있는 상태에서 코드 진행중입니다.
해당 블루투스 장비의 UUID는 "00001812-0000-1000-8000-00805f9b34fb" 입니다.
private class ClientThread extends Thread{
private BluetoothSocket mmCSocket = null;
public ClientThread(BluetoothDevice device) {
BluetoothSocket tmp = null;
try {
UUID _UUID = UUID.fromString("00001812-0000-1000-8000-00805f9b34fb");
tmp = device.createInsecureRfcommSocketToServiceRecord(_UUID);
mmCSocket = tmp;
} catch (IOException e) {
e.printStackTrace();
return;
}
}
@Override
public void run() {
// 원격 디바이스와 접속 시도
mBTAdapter.cancelDiscovery();
try {
mmCSocket.connect();
} catch (IOException e) {
e.printStackTrace();
try {
mmCSocket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return;
}
Util_LogMsg logMsg = new Util_LogMsg();
Dlog.d(logMsg.log());
// 원격 디바이스와 접속되었으면 데이서 송수신 스레드를 시작
onConnected(mmCSocket);
}
public void cancel(){
try {
mmCSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
mmCSocket.connect(); 이부분에서 연결을 시도하면 연결이 안되고 아래의 로그가 찍힙니다.
02-29 18:30:14.711 5972-6468/com.laone.smartpen W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
02-29 18:30:14.711 5972-6468/com.laone.smartpen W/System.err: at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:739)
02-29 18:30:14.711 5972-6468/com.laone.smartpen W/System.err: at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:750)
02-29 18:30:14.711 5972-6468/com.laone.smartpen W/System.err: at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:478)