2016-08-02 2 views
0

c로 작성된 BLUETOOTH 서버를 시작한 후.Android 응용 프로그램을 사용하여 Bluetooth 서비스를 찾을 수 없습니다.

https://github.com/RyanGlScott/BluetoothTest/blob/master/C%20BlueZ%20Server/bluez_server.c

이 명령의 출력이 지역 검색 sdptool입니다 :

....other services.... 

    Service Name: AVRCP CT 
    Service RecHandle: 0x10005 
    Service Class ID List: 
     "AV Remote" (0x110e) 
    Protocol Descriptor List: 
     "L2CAP" (0x0100) 
     PSM: 23 
     "AVCTP" (0x0017) 
     uint16: 0x103 
    Profile Descriptor List: 
     "AV Remote" (0x110e) 
     Version: 0x0100 


    /*MY SERVICE!!!*/ 
    Service Name: Armatus Bluetooth server 
    Service Description: A HERMIT server that interfaces with the Armatus Android app 
    Service Provider: Armatus 
    Service RecHandle: 0x10006 
    Service Class ID List: 
     "Serial Port" (0x1101) 
    Protocol Descriptor List: 
     "L2CAP" (0x0100) 
     "RFCOMM" (0x0003) 
     Channel: 3 
    Profile Descriptor List: 
     "Serial Port" (0x1101) 
     Version: 0x0100 

....other services.... 

I'am는 안드로이드 응용 프로그램

// Create a BroadcastReceiver for ACTION_FOUND 
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { 

     public void onReceive(Context context, Intent intent) { 
      String action = intent.getAction(); 
      // Whenever a remote Bluetooth device is found 
      if (BluetoothDevice.ACTION_FOUND.equals(action)) { 
       // Get the BluetoothDevice object from the Intent 
       BluetoothDevice bluetoothDevice = 
       intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
       // Add the name and address to an array adapter to show in a ListView 
       adapter.add(bluetoothDevice.getName() + "\n" 
         + bluetoothDevice.getAddress()); 


       if (bluetoothDevice.getName().equals("mint-0")) { 
        Log.d("tagmint0","bene bene"); 

        try { 

        ParcelUuid[] uuids = (ParcelUuid[]) bluetoothDevice.getUuids(); 


        for (ParcelUuid uuid : uuids) { 
         Log.d("x", "mintUUIDxx: " + uuid.getUuid().toString() + "\n"); 

        } 



        } catch (Exception e) { 
        e.printStackTrace(); 
        } 

       } 
      } 
     } 
    }; 

내 질문은

를 사용하여이 서비스를 찾기 위해 노력하고, sdptool browse local 명령을 사용하여 내 안드로이드 응용 프로그램이 내 서비스를 찾을 수없는 이유는 무엇입니까?

이 안드로이드 응용 프로그램의 출력은 서버의 UUID를 포함하지 않습니다 당신이 볼 수 있듯이

mintUUIDxx: 0000111e-0000-1000-8000-00805f9b34fb 
mintUUIDxx: 00001105-0000-1000-8000-00805f9b34fb 
mintUUIDxx: 00001106-0000-1000-8000-00805f9b34fb 
mintUUIDxx: 0000112d-0000-1000-8000-00805f9b34fb 
mintUUIDxx: 0000110e-0000-1000-8000-00805f9b34fb 
mintUUIDxx: 00001112-0000-1000-8000-00805f9b34fb 
mintUUIDxx: 0000111f-0000-1000-8000-00805f9b34fb 
mintUUIDxx: 00000000-0000-1000-8000-00805f9b34fb 

에게 있습니다. 누군가 왜 나를 설명 할 수 있을까요?

답변

0

bluetoothDevice.getUuids();

이 방법은 원격 장치에서 UUID를 검색하는 서비스 검색 절차를 시작하지 않습니다. 대신 서비스 UUID의 로컬 캐시 사본이 리턴됩니다.

대신 fetchUuidsWithSdp()을 사용하십시오. 이 방법은 원격 장치에서 서비스 검색을 수행하여 지원되는 UUID를 가져옵니다.

+0

와 bluez_server.c에 그 라인을 변경하여 사용 해보세요, 그래서 사용 이런 식으로 : 'bluetoothDevice.fetchUuidsWithSdp(); ParcelUuid [] uuids = (ParcelUuid []) bluetoothDevice.getUuids(); (ParcelUuid uuid : uuids) { Log.d ("x", "mintUUIDxx :"+ uuid.getUuid(). toString() + "\ n"); } 아무 것도 변경되지 않습니다. – Franconet

+0

@Franconet 자신의 서비스의 UUID를 사용하여 기기에 연결을 시도 할 수 있습니다. 자세한 내용은 [여기] (http://stackoverflow.com/questions/25658426/android-bluetooth-fetchuuidswithsdp-does-not-return-all-uuids-on-some-devices)입니다. –

0

동일한 자식 코드를 사용한 경우 Android에서 다른 UUID를 언급 한 것처럼 보입니다. 당신이

uint32_t svc_uuid_int[] = { 0x01110000, 0x00100000, 0x80000080, 0xFB349B5F }; 

그리고 안드로이드 출력을 bluez_server.c에서

mintUUIDxx: 0000111e-0000-1000-8000-00805f9b34fb 

그것은 논리 값을 반환이

uint32_t svc_uuid_int[] = { 0x0000111e, 0x00001000, 0x80000080, 0x5f9b34fb }; 
+0

두 응용 프로그램에서 동일한 UUID를 사용했습니다. 그런데, 고마워요 :) – Franconet

+0

다음 rfcomm-server.c를 사용했습니다. 조금 수정되었지만 안드로이드 응용 프로그램 BlueTerm에서 데이터를 모두받을 수 있습니다 : -https : //play.google.com/store/apps/ details? id = es.pymasde.blueterm & hl = en 코드 : - http://pastebin.com/ntpNkaJS – HallMark

관련 문제