gpt4 book ai didi

java - fetchUuidWithSdp 总是给出缓存的 UUID

转载 作者:行者123 更新时间:2023-12-05 00:07:41 24 4
gpt4 key购买 nike

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

最佳答案

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

Android 将设备的 SDP UUID 记录与设备的蓝牙地址一起缓存,因此如果您更改服务的 UUID 而不是设备的蓝牙地址,Android 的列表中仍将有旧的缓存 UUID在设备上调用 getUuids() 时的 UUID。

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

关于java - fetchUuidWithSdp 总是给出缓存的 UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12262679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com