问题描述
我注意到,当配对的蓝牙设备都有一个名称的改变,我的Android设备并不总是注册该名称的变化。它继续显示设备的老字号......这不是没有配对设备的一个问题,所以我自然的猜测是,Android的缓存配对设备的名称的地方。
I noticed that when a paired Bluetooth device has a name change, my Android device doesn't always register that name change. It continues to display the old name of the device... This isn't a problem for unpaired devices, so my natural guess is that Android caches the names of paired devices somewhere.
在环顾四周,我发现,如果我解除配对的装置和手动清除存储在我的Android的蓝牙共享的应用程序缓存,这个问题消失。当然,这个问题很可能会回来后,我再次配对的设备我的Android。
After looking around, I found that if I unpair the device and manually clear the cache stored in my Android's "Bluetooth Share" app, this problem goes away. Of course, the problem will probably come back after I pair the device again to my Android.
TL; DR如何强制的Android始终显示蓝牙设备的最新名称
我听说一些关于fetchUuidsWithSdp的方法,但我不知道如何使用它。
I heard something about the "fetchUuidsWithSdp" method, but I'm not sure how to use it.
推荐答案
是的,fetchUuidsWithSdp()是一个好主意,因为它不像getUuids()它迫使设备尝试连接到目标设备并更新它的它的相关信息
Yes, fetchUuidsWithSdp() is a good idea because, unlike getUuids() it forces the device to attempt to connect to the destination device and update it's information about it.
有关fetchUuidsWithSdp的官方支持刚添加的4.0.3,但它是可用的使用反射了。
Official support for fetchUuidsWithSdp was just added in 4.0.3, but it was available before that using reflection.
public static void startFetch( BluetoothDevice device ) {
// Need to use reflection prior to API 15
Class cl = null;
try {
cl = Class.forName("android.bluetooth.BluetoothDevice");
} catch( ClassNotFoundException exc ) {
Log.e(CTAG, "android.bluetooth.BluetoothDevice not found." );
}
if (null != cl) {
Class[] param = {};
Method method = null;
try {
method = cl.getMethod("fetchUuidsWithSdp", param);
} catch( NoSuchMethodException exc ) {
Log.e(CTAG, "fetchUuidsWithSdp not found." );
}
if (null != method) {
Object[] args = {};
try {
method.invoke(device, args);
} catch (Exception exc) {
Log.e(CTAG, "Failed to invoke fetchUuidsWithSdp method." );
}
}
}
}
人们通常会再注册android.bluetooth.device.action.UUID,但你可能要注册的名称变化行动吧。
One would normally then register for android.bluetooth.device.action.UUID, but you might want to register for the name change action instead.
需要注意的是,如果你决定报名参加UUID的行动,这是前15 API为android.bleutooth.device.action.UUID(电子和u蓝牙互换)拼写错误。
Note that, if you do decide to register for the UUID action, it was misspelled prior to API 15 as "android.bleutooth.device.action.UUID" (the e and u in bluetooth are swapped).
这篇关于如何以编程方式清除Android的蓝牙名称缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!