안드로이드와 블루투스 스캐너 연결을 하기위해 영상털리범님의 블로그에 있는걸로 테스트중
setState() 0 -> 2
BEGIN mConnectThread
isSocketAllowedBySecurityPolicy start : device null
getBluetoothService() called with no BluetoothManagerCallback
connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[45]}
endAllStagingAnimators on 0xb43a5e00 (ListView) with handle 0xb432db70
Timeline: Activity_idle id: android.os.BinderProxy@360401a6 time:164576375
setState() 2 -> 1
Connect Fail
close() in, this: android.bluetooth.BluetoothSocket@3c9f05ec, channel: -1, state: INIT
이러한 에러메시지가 나옵니다.
소스코드는
private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device) {
mmDevice = device;
BluetoothSocket tmp = null;
/*
* / // 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);
*
* try { Method m = device.getClass().getMethod(
* "createInsecureRfcommSocket", new Class[] { int.class }); try {
* tmp = (BluetoothSocket) m.invoke(device, 15); } catch
* (IllegalArgumentException e) { // TODO Auto-generated catch block
* e.printStackTrace(); } catch (IllegalAccessException e) { // TODO
* Auto-generated catch block e.printStackTrace(); } catch
* (InvocationTargetException e) { // TODO Auto-generated catch
* block e.printStackTrace(); }
*
* } catch (NoSuchMethodException e) { // TODO Auto-generated catch
* block e.printStackTrace(); } } catch (IOException e) { } /
*/
// 디바이스 정보를 얻어서 BluetoothSocket 생성
try {
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
Log.e(TAG, "create() failed", e);
}
mmSocket = tmp;
}
public void run() {
Log.i(TAG, "BEGIN mConnectThread");
setName("ConnectThread");
// 연결을 시도하기 전에는 항상 기기 검색을 중지한다.
// 기기 검색이 계속되면 연결속도가 느려지기 때문이다.
btAdapter.cancelDiscovery();
// BluetoothSocket 연결 시도
try {
// BluetoothSocket 연결 시도에 대한 return 값은 succes 또는 exception이다.
mmSocket.connect();
Log.d(TAG, "Connect Success");
} catch (IOException e) {
connectionFailed(); // 연결 실패시 불러오는 메소드
Log.d(TAG, "Connect Fail");
// socket을 닫는다.
try {
mmSocket.close();
} catch (IOException e2) {
Log.e(TAG,
"unable to close() socket during connection failure",
e2);
}
// 연결중? 혹은 연결 대기상태인 메소드를 호출한다.
BluetoothService.this.start();
return;
}
// ConnectThread 클래스를 reset한다.
synchronized (BluetoothService.this) {
mConnectThread = null;
}
// ConnectThread를 시작한다.
connected(mmSocket, mmDevice);
}
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) {
Log.e(TAG, "close() of connect socket failed", e);
}
}
}
uuid문제라고 하는데 uuid쪽을 변경해도 잘안되서요 혹시 어떤문제인지 알수있나해서 질문올려봅니다