我如何获得蓝牙设备的UUID?蓝牙、如何获得、设备、UUID

2023-09-06 00:40:37 作者:情深似海不如沉入大海

我需要知道的UUID的API 8(2.2)或者可能2.3.3。

据我所知的文档,这应该是允许的:

  phoneDevice = blueAdapter.getRemoteDevice(phoneAddress);
    ParcelUuid [] phoneUuids = phoneDevice.getUuids(); //不能编译
 

Eclipse的给我: 的方法getUuids()是未定义BluetoothDevice类的类型。的 但见: http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids()

另外,我想知道怎样的UUID被瓜分的ParcelUuid []内。如果我曾经管理到那里,我怎么找回从parcelUuid []一个UUID?文档Android的蓝牙似乎是很差,在我看来。

真是笑话! 现在,我试着从意图得到它,​​但是这也给了:*EXTRA_UUID不能得到解决或不是场*:

  intent.getParcelableExtra(BluetoothDevice.EXTRA_UUID);
 

解决方案 笔记本电脑已经连接蓝牙耳机,但是播放设备不显示蓝牙耳机是为何

您必须使用反射来使用的Andr​​oid版本和LT的getUuids()和fetchUuidsWithSdp(); 3.所以,尽量在code:

 方法方法= phoneDevice.getClass()实现getMethod(getUuids,NULL);
ParcelUuid [] phoneUuids =(ParcelUuid [])method.invoke(phoneDevice,NULL);
 

I need to know UUID on API 8 (2.2) or possibly 2.3.3.

As I understand the documentation, this should be allowed:

    phoneDevice = blueAdapter.getRemoteDevice(phoneAddress);
    ParcelUuid[] phoneUuids = phoneDevice.getUuids();  // Won't compile

Eclipse gives me: "The method getUuids() is undefined for the type BluetoothDevice." But see: http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids()

Also, I would like to know how the UUIDs are "parceled" inside the ParcelUuid[]. In case I ever manage to get there, how do I retrieve a UUID from a parcelUuid[]? Documentation for Android bluetooth seems to be very poor, in my opinion.

What a joke! Now I try to get it from the intent, but this too gives: *"EXTRA_UUID cannot be resolved or is not a field"*:

intent.getParcelableExtra(BluetoothDevice.EXTRA_UUID); 

解决方案

You have to use reflection to use the getUuids() and fetchUuidsWithSdp() on android version < 3. So, try the code:

Method method = phoneDevice.getClass().getMethod("getUuids", null);
ParcelUuid[] phoneUuids = (ParcelUuid[]) method.invoke(phoneDevice, null);