3

我正在编写一个应用程序,在该应用程序中我必须在选定的设备上进行服务发现,但是每当我执行 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;

}

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

这是日志猫:

这是开始发现时的错误:

 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 的意图作为错误

 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。

4

1 回答 1

0

我看到这是一篇旧帖子,但它是我在 Google 搜索关于 Android 和服务发现协议 (SDP) 中缓存的 UUID 的第一个结果

Android会缓存设备的SDP UUID记录和设备的蓝牙地址,所以如果你改变你的服务的UUID而不是设备的蓝牙地址,Android调用时UUID列表中仍然会有旧缓存的UUID设备上的 getUuids()。

摆脱缓存的 UUID 记录的唯一方法是在 Android 系统设置中重置网络设置。似乎不可能以编程方式清除缓存。

于 2021-06-24T07:34:01.607 回答