2012-01-04 7 views
1

두 개의 Samsung Galaxy Tab 간의 통신을 테스트하기 위해 BluetoothChat 예제 (3.1) 코드 샘플을 사용하고 있습니다. 전에 여러 번 물어 봤지만 아직도 이런 일을 할 때 혼란 스럽습니다.블루투스 장치 연결 시도 중 연결이 거부되었습니다.

BluetoothSocket mmSocket 
... 
mmSocket.connect(); 

이렇게하면 연결이 거부됩니다. 필자는 아무런 결과없이 프로그램 외부와 내부에서 페어링 및 페어링을 여러 번 시도했습니다. 누구든지 아이디어가 있습니까? (답변에서 추가)

업데이트 : 모두 클라이언트 & 서버

코드는 동일합니다. 이들은 실제로 두 개의 삼성 갤럭시 탭 (3.1)입니다. 원격 장치에 연결하는 동안 오류가 발생합니다. 34 :

  • 01 ~ 05 10 :

    private class AcceptThread extends Thread { 
        // The local server socket 
        private final BluetoothServerSocket mmServerSocket; 
        private String mSocketType; 
    
        public AcceptThread(boolean secure) { 
         BluetoothServerSocket tmp = null; 
         mSocketType = secure ? "Secure":"Insecure"; 
    
         // Create a new listening server socket 
         try { 
          if (secure) { 
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); 
          } else { 
    
           tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
             NAME_INSECURE, UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));      
          } 
         } catch (IOException e) { 
          Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e); 
         } 
         mmServerSocket = tmp; 
        } 
    
        public void run() { 
         if (D) Log.d(TAG, "Socket Type: " + mSocketType + 
           "BEGIN mAcceptThread" + this); 
         setName("AcceptThread" + mSocketType); 
    
         BluetoothSocket socket = null; 
    
         // Listen to the server socket if we're not connected 
         while (mState != STATE_CONNECTED) { 
          try { 
           // This is a blocking call and will only return on a 
           // successful connection or an exception 
           socket = mmServerSocket.accept(); 
          } catch (IOException e) { 
           Log.e("Ali", "Error while connecting to device because: "+ e.getStackTrace()); 
           break; 
          } 
    
          // If a connection was accepted 
          if (socket != null) { 
           synchronized (BluetoothChatService.this) { 
            switch (mState) { 
            case STATE_LISTEN: 
            case STATE_CONNECTING: 
             // Situation normal. Start the connected thread. 
             connected(socket, socket.getRemoteDevice(), 
               mSocketType); 
             break; 
            case STATE_NONE: 
            case STATE_CONNECTED: 
             // Either not ready or already connected. Terminate new socket. 
             try { 
              socket.close(); 
             } catch (IOException e) { 
              Log.e(TAG, "Could not close unwanted socket", e); 
             } 
             break; 
            } 
           } 
          } 
         } 
         if (D) Log.i(TAG, "END mAcceptThread, socket Type: " + mSocketType); 
    
        } 
    

    을 마지막으로 여기에 당신이 로그 캣을 다음과 같이

     public ConnectThread(BluetoothDevice device, boolean secure) { 
         mmDevice = device; 
         BluetoothSocket tmp = null; 
         mSocketType = secure ? "Secure" : "Insecure"; 
    
         // Get a BluetoothSocket for a connection with the 
         // given BluetoothDevice 
         try { 
          if (secure) { 
           //tmp = device.createRfcommSocketToServiceRecord(
             //MY_UUID_SECURE); 
    //     tmp = device.createRfcommSocketToServiceRecord(
    //       UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); 
           Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); 
           tmp = (BluetoothSocket) m.invoke(device, 1);      
    
          } else {      
            Method m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] {int.class}); 
            tmp = (BluetoothSocket)m.invoke(device, UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));     
    
          } 
         } catch (Exception e) { 
          Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e); 
         } 
         mmSocket = tmp; 
        } 
    
        public void run() { 
         Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType); 
         setName("ConnectThread" + mSocketType); 
    
         // Always cancel discovery because it will slow down a connection 
         mAdapter.cancelDiscovery(); 
    
         // Make a connection to the BluetoothSocket 
         try { 
          // This is a blocking call and will only return on a 
          // successful connection or an exception 
          mmSocket.connect(); 
         } catch (IOException e) { 
          // Close the socket 
          try { 
           Log.e("Ali", "Error interacting with remote device. Here is the cause: "+ e.getMessage()); 
           mmSocket.close(); 
          } catch (IOException e2) { 
           Log.e(TAG, "unable to close() " + mSocketType + 
             " socket during connection failure", e2); 
          } 
          connectionFailed(); 
          return; 
         } 
    
         // Reset the ConnectThread because we're done 
         synchronized (BluetoothChatService.this) { 
          mConnectThread = null; 
         } 
    
         // Start the connected thread 
         connected(mmSocket, mmDevice, mSocketType); 
        } 
    

    청취 부분은 07.749 : E/BluetoothChat (22495) : +++ ON CREATE +++ 01-05 012 (ON) ++ 01-05

  • 10 : 37 : 41.109 : E/BluetoothChat (22599) : ++ ON START ++ 01-05
  • 10 : 37 : 50.009 : D/BluetoothChat (22,599) -1 onActivityResult를 01-05
  • 10 : 37 : 50.009 : D/BluetoothChatService (22,599)에 연결 :
  • 60 : D0 : A9 : 85 : AE : 6A 01-05 10 : 37 : 50.009 : D/BluetoothChatService (22599) :
  • setState() 1 -> 2 01-05 10 : 37 : 50.009 : E/BluetoothChat (22599) : + ON
  • RESUME + 01-05 10 : 37 : 50.029 : I/Bluetooth ChatService (22599) : BEGIN
  • mConnectThread SocketType : 보안 01 ~ 05 10 : 37 : 50.029 :
  • I/BluetoothChat (22599) : MESSAGE_STATE_CHANGE : 2 01 ~ 05 10 : 37 : 55.169 :
  • E/알리 (22599) : 원격 장치와 상호 작용하는 중 오류가 발생했습니다. 호스트가 다운 됨 01-05 10 : 37 : 55.169 :
  • D/BluetoothChatService (22599) : 시작 01-05 10 : 37 : 55.169 :
  • D/BluetoothChatService (22599) : setState() 2 -> 1 인 01-05 10 : 37 : 55.189 :
  • I/BluetoothChat (22,599) MESSAGE_STATE_CHANGE : 1 01-05 10 : 37 : 55.219 :
  • D/dalvikvm (22,599)가 171K GC_CONCURRENT 해방 4 % 무료 6522K/6791K, 일시 정지 2ms의 + 3ms의 01 ~ 05 10 : 38 : 02.749 :
  • W/PhoneWindow (22599) : 오디오 관리자를 가져올 수 없습니다 01 ~ 05 10 : 38 : 04.969 :
  • E/BluetoothChat (22599) : - 일시 중지시 - 01-05 10 : 38 : 04.989 :
  • I/ApplicationPackageManager (22599) : cscCountry가 독일어가 아닙니다. TPH 01-05 10 : 38 : 07.059 :
  • D/DeviceListActivity (22599) : doDiscovery() 01-05 10:38:10.609 :
  • D/BluetoothChat (22,599) -1 onActivityResult를 01-05 10 : 38 : 10.609 :
  • D/BluetoothChatService은 (22,599)는 : F0 : 08 : 연결 F1 : 5E : 51 : 67 01- 05 : 10 : 38 : 10.609 :
  • D/BluetoothChatService (22599) : setState() 1 -> 2 01-05 10 : 38 : 10.609 :
  • E/BluetoothChat (22599) : + ON RESUME + 01-05 10 : 38 : 10.609 :
  • I/BluetoothChatService (22,599)을 mConnectThread SocketType BEGIN : 보안 01-05 10 : 38 : 10.629 :
  • I/BluetoothChat (22,599) MESSAGE_STATE_CHANGE : 2 01-05 10시 38분 : 12.089 :
  • E/BluetoothChat (22599) : - 일시 중지시 - 01-05 10 : 38 : 12.329 :
  • D/CLIPBOARD (22599) : 시작 입력시 클립 보드 대화 상자 숨기기 ... 다른 사용자가 완료했습니다 ...! 01-05 10 : 38 : 12.339 :
  • W/IInputConnectionWrapper (22,599)에 비활성 InputConnection showStatusIcon 01-05 10 : 38 : 19.589 :
  • E/BluetoothChat (22,599) + RESUME ON + 01-05 10 : 38 : 20.799 :
  • E/Ali (22599) : 원격 장치와 상호 작용하는 중 오류가 발생했습니다. 여기 원인 : 38 : 20.799 :
  • D/BluetoothChatService (22599) : 38 : 20.799 :
  • D/BluetoothChatService (22,599) : 01-05 10 입문서 연결이 01-05 10 setState를 거부를 () 2 -> 1 인 01-05 10 : 38 : 20.799 :
  • I/BluetoothChat (22,599) MESSAGE_STATE_CHANGE : 1 01-05 10 : 39 : 23.489 :
  • E/BluetoothChat (22,599) - PAUSE ON -
+0

Pls가 서버 및 클라이언트 측의 관련 코드를 게시합니다. 또한 오류가 기록됩니다 .. –

답변

0

거부해야 할 다른 이유는 다음과 같습니다. - 잘못된 rfcomm 포트 -black list - 다른 장치의 MAC 주소가 잘못되었습니다.

+0

그러면 해결책은 무엇입니까? 나는 수동으로 맥 주소를 입력하여 맥 주소를 테스트했는데 나는 맥 주소가 문제가 아니라는 것을 이해했다. 문제를 어떻게 현지화 할 수 있습니까? –

+0

나는 반사 된 방법으로 결과를 아직 테스트하지 못했습니다. –

+0

두 장치를 페어링 할 수 있지만 장치를 연결할 수 없습니다. 제발 도와주세요 –

관련 문제