Android的 - 获取蓝牙UUID该设备 [英] Android - Get Bluetooth UUID for this device
问题描述
我褐变栈和互联网的简单的解决方案来获得设备的我目前使用的 UUID
。我绊了帖子这样但他们都不似乎帮助我。
I was browing Stack and the internet for a simple solution to get the UUID
of the device I'm currently using. I stumbled over posts like this but none of them seemed to help me.
doc文件告诉我,<一个href=\"http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids%28%29\">about这 getUuids()
的功能,但通过DOC去为的 Android的蓝牙我最终有一个<一个href=\"http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html\">BluetoothAdapter但我需要一个 BluetoothDevice类
来执行此功能。
The doc tells me about this getUuids()
function but when going through the doc for Android Bluetooth I end up having a BluetoothAdapter but I need a BluetoothDevice
to execute this function.
所以,我需要了解以下内容:
So I need to know the following:
1)函数返回真正的设备 UUID
?由于名称甾体抗炎药复数(getUuid 取值
)
1) Is the function returning really the device UUID
? Because the name saids plural (getUuids
)
2)我如何得到这个实例 BluetoothDevice类
?
2) How do I get an instance of this BluetoothDevice
?
谢谢!
推荐答案
使用反射,你可以调用隐藏方法 getUuids()
在 BluetoothAdater
:
Using reflection you can invoke the hidden method getUuids()
on the BluetoothAdater
:
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
ParcelUuid[] uuids = (ParcelUuid[]) getUuidsMethod.invoke(adapter, null);
for (ParcelUuid uuid: uuids) {
Log.d(TAG, "UUID: " + uuid.getUuid().toString());
}
这是在Nexus S的结果:
This is the result on a Nexus S:
UUID: 00001000-0000-1000-8000-00805f9b34fb
UUID: 00001001-0000-1000-8000-00805f9b34fb
UUID: 00001200-0000-1000-8000-00805f9b34fb
UUID: 0000110a-0000-1000-8000-00805f9b34fb
UUID: 0000110c-0000-1000-8000-00805f9b34fb
UUID: 00001112-0000-1000-8000-00805f9b34fb
UUID: 00001105-0000-1000-8000-00805f9b34fb
UUID: 0000111f-0000-1000-8000-00805f9b34fb
UUID: 0000112f-0000-1000-8000-00805f9b34fb
UUID: 00001116-0000-1000-8000-00805f9b34fb
其中,例如, 0000111f-0000-1000-8000-00805f9b34fb
是 HandsfreeAudioGatewayServiceClass
和 00001105-0000-1000-8000-00805f9b34fb
是 OBEXObjectPushServiceClass
。这种方法的实际可用性可能取决于设备和固件版本。
where, for instance, 0000111f-0000-1000-8000-00805f9b34fb
is for HandsfreeAudioGatewayServiceClass
and 00001105-0000-1000-8000-00805f9b34fb
is for OBEXObjectPushServiceClass
. Actual availability of this method may depend on device and firmware version.
这篇关于Android的 - 获取蓝牙UUID该设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!