Android - 获取此设备的蓝牙 UUID [英] Android - Get Bluetooth UUID for this device

查看:95
本文介绍了Android - 获取此设备的蓝牙 UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Stack 和互联网上浏览了一个简单的解决方案来获取我当前使用的设备的 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.

文档告诉我关于这个 getUuids() 函数,但在查看 Android 蓝牙 我最终有一个 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?因为名字表示复数 (getUuids)

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?

谢谢!

推荐答案

使用反射可以调用BluetoothAdater上的隐藏方法getUuids():

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 用于 HandsfreeAudioGatewayServiceClass00001105-0000-1000-8005f9b34fb> 用于 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆