Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android BluetoothAdapter getRemoteDevice已缓存_Android_Bluetooth - Fatal编程技术网

Android BluetoothAdapter getRemoteDevice已缓存

Android BluetoothAdapter getRemoteDevice已缓存,android,bluetooth,Android,Bluetooth,我正在开发一个Android应用程序,使用蓝牙低能耗。 我的代码逻辑包括使用BluetoothAdapter和方法getRemoteDevice(MAC AddAddress) 问题是,当我使用这个方法时,Android似乎已经缓存了它。因为当我没有关闭或设备未打开时,它仍然会创建名为的BluetoothDevice对象。但我当然无法连接 我如何防止Android缓存这个旧的Bluetooth设备 我试过用思考 Method m=device.getClass().getMethod(“remo

我正在开发一个Android应用程序,使用蓝牙低能耗。 我的代码逻辑包括使用BluetoothAdapter和方法getRemoteDevice(MAC AddAddress)

问题是,当我使用这个方法时,Android似乎已经缓存了它。因为当我没有关闭或设备未打开时,它仍然会创建名为的BluetoothDevice对象。但我当然无法连接

我如何防止Android缓存这个旧的Bluetooth设备

我试过用思考

Method m=device.getClass().getMethod(“removeBond”,(Class[])null;
m、 调用(设备,(对象[])null)

但它不会产生任何更好的结果

谢谢大家!

根据:

BluetoothDevice将始终返回有效硬件 地址,即使此适配器从未见过该设备

因此,它不是缓存结果,它只是创建一个愚蠢的BluetoothDevice对象,它甚至不知道MAC地址是否存在


您可以尝试连接到设备的GATT服务,或启动发现,或使用LE scanner对象,并使用适当的回调来检查连接是否成功。

同样的代码对我来说工作得非常好。可能您需要在不同品牌的设备中进行测试。蓝牙代码在每个品牌上的表现都不同。你最终找到了这个问题的解决方案吗?@IgorGanapolsky不,我还没有找到任何解决方案。如果“找到的”设备没有在限制内响应,我就使用超时函数中止连接。