fetchUuidWithSdp总是给出缓存的UUID

我正在编写一个应用程序,我必须在选定的设备上进行服务发现,但每当我在做一个fetchUuid时,它总是在远程设备上给我缓存的UUID。

这是我正在尝试的

public boolean UUIDsearch(BluetoothDevice device){ t=device.fetchUuidsWithSdp(); Log.d(TAG,"Device class = :"+device.getClass()); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent intent) { String action = intent.getAction(); //BluetoothDevice deviceExtra = intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE"); if (BluetoothDevice.ACTION_UUID.equals(action)){ uuidExtra =intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID"); } Log.d(TAG,"SDP has no errors: = "+t); // if(found==false){ for(int i=0;i<uuidExtra.length;i++){ Log.d(TAG,"UUID: "+ uuidExtra[i]); if((uuidExtra[i].toString()).equals(MY_UUID.toString())){ found=true; Log.d(TAG,"Match found in loop"); } } // } } }; // Register the BroadcastReceiver IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_UUID); registerReceiver(mReceiver, filter1); return true; } 

有人能告诉我代码有什么问题。

这是logcat:

这是开始descovery时的错误:

  09-05 15:05:15.906: D/(32591): bta_jv_start_discovery_cback: p_sdp_rec:0x52ab0e4c 09-05 15:05:15.906: D/BTIF_SOCK(32591): jv_dm_cback: event:8, slot id:26 09-05 15:05:15.906: E/BTIF_SOCK(32591): ## ERROR : jv_dm_cback: BTA_JV_DISCOVERY_COMP_EVT, slot id:26, found channle #, status:0, scn:7## 09-05 15:05:15.906: I/(32591): BTA_JvRfcommConnect 09-05 15:05:15.910: D/BluetoothSocket(2100): inputStream.read ret: 4 09-05 15:05:15.910: D/(32591): releasing SDP rsp_list 

发生上述错误后,fetchUuidWithSdp()返回具有缓存的UUID作为错误的intent

  09-04 16:54:51.851: I/(24860): BTA got event 0x206 09-04 16:54:51.851: I/(24860): btif_dm_search_services_evt: event = 2 09-04 16:54:51.851: D/(24860): btif_dm_search_services_evt:(result=0x0, services 0xa42ed8f) 09-04 16:54:51.851: E/(24860): Index: 0 uuid:00001101-0000-1000-8000-00805f9b34fb 09-04 16:54:51.851: E/(24860): Index: 1 uuid:00001103-0000-1000-8000-00805f9b34fb 09-04 16:54:51.851: E/(24860): Index: 2 uuid:0000110a-0000-1000-8000-00805f9b34fb 09-04 16:54:51.851: E/(24860): Index: 3 uuid:00001105-0000-1000-8000-00805f9b34fb 09-04 16:54:51.851: E/(24860): Index: 4 uuid:00001106-0000-1000-8000-00805f9b34fb 09-04 16:54:51.851: E/(24860): Index: 5 uuid:00001110-0000-1000-8000-00805f9b34fb 09-04 16:54:51.851: E/(24860): Index: 6 uuid:00001104-0000-1000-8000-00805f9b34fb 09-04 16:54:51.851: E/(24860): Index: 7 uuid:0000111b-0000-1000-8000-00805f9b34fb 09-04 16:54:51.855: E/(24860): Index: 8 uuid:00001115-0000-1000-8000-00805f9b34fb 09-04 16:54:51.855: E/(24860): Index: 9 uuid:00001116-0000-1000-8000-00805f9b34fb 09-04 16:54:51.855: E/(24860): Index: 10 uuid:0000112d-0000-1000-8000-00805f9b34fb 09-04 16:54:51.855: E/(24860): Index: 11 uuid:0000112f-0000-1000-8000-00805f9b34fb 09-04 16:54:51.855: E/(24860): Index: 12 uuid:00001132-0000-1000-8000-00805f9b34fb 09-04 16:54:51.855: E/(24860): Index: 13 uuid:00001400-0000-1000-8000-00805f9b34fb 09-04 16:54:51.855: D/(24860): btif_dm_search_services_evt Remote Service SDP done. Call bond_state_changed_cb BONDED 09-04 16:54:51.855: D/(24860): bond_state_changed: state=2 prev_state=1 09-04 16:54:51.855: D/(24860): HAL bt_hal_cbacks->bond_state_changed_cb 09-04 16:54:51.855: I/(24860): bta_dm_search_sm_execute state:3, event:0x206 09-04 16:54:51.855: D/(24860): bta_dm_search_cmpl 09-04 16:55:59.703: E/BluetoothRemoteDevices(24860): aclStateChangeCallback: State:DisConnected to Device:00:0A:3A:64:A7:34 

上述UUID被标记为错误,因为fetchUuidWithSdp在服务发现中遇到错误时返回缓存的UUID,或者需要很长时间才能执行相同操作。