我如何获得蓝牙设备的UUID? [英] How do I get the UUID of a bluetooth device?

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

问题描述

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

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

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

Eclipse的给我: 的方法getUuids()是未定义BluetoothDevice类的类型。的 但见: <一href="http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids">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);

这篇关于我如何获得蓝牙设备的UUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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