마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 블루투스 연결

0 추천
안드로이드와 블루투스 스캐너 연결을 하기위해 영상털리범님의 블로그에 있는걸로 테스트중

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쪽을 변경해도 잘안되서요 혹시 어떤문제인지 알수있나해서 질문올려봅니다
세일인 (120 포인트) 님이 2015년 10월 20일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...