博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android - Get Bluetooth UUID for this device
阅读量:6428 次
发布时间:2019-06-23

本文共 3103 字,大约阅读时间需要 10 分钟。

Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

9
7

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 but none of them seemed to help me.

The doc tells me getUuids() function but when going through the doc for I end up having a but I need a BluetoothDevice to execute this function.

So I need to know the following:

1) Is the function returning really the device UUID? Because the name saids plural (getUuids)

2) How do I get an instance of this BluetoothDevice?

Thanks!

 
    
anyway, how could you know the UUID is for your bluetooth device @Ron? –  Jul 7 '14 at 7:23

1 Answer

13 accepted

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());}

This is the result on a Nexus S:

UUID: 00001000-0000-1000-8000-00805f9b34fbUUID: 00001001-0000-1000-8000-00805f9b34fbUUID: 00001200-0000-1000-8000-00805f9b34fbUUID: 0000110a-0000-1000-8000-00805f9b34fbUUID: 0000110c-0000-1000-8000-00805f9b34fbUUID: 00001112-0000-1000-8000-00805f9b34fbUUID: 00001105-0000-1000-8000-00805f9b34fbUUID: 0000111f-0000-1000-8000-00805f9b34fbUUID: 0000112f-0000-1000-8000-00805f9b34fbUUID: 00001116-0000-1000-8000-00805f9b34fb

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.

 
    
I'm using SDK16 and it doesn't work for me. The uuids are null. Furthermore I'd like to have just my Bluetooth uuid. Do you know how to get this one? –  Oct 29 '13 at 8:08
    
There is an uuid for each Bluetooth service exposed by the device; that's why you see multiple uuids for the smartphone. I performed the tests using SDK on Nexus S with Android 4.1.2 and Galaxy Nexus with Android 4.3. Which device did you use? –  Oct 29 '13 at 9:34
1  
Bluetooth has to be on. I tested on a Galaxy S2 with Android 4.1.2 and it worked, showing 12 UUIDs. –  Oct 29 '13 at 13:10
2  
Ok, thats great so far - thanks :) But how do I get THE uuid representing my phone? Or do I need all of them for identifying my devide? –  Nov 4 '13 at 15:08
1  
@Ron, have you got what you wanted? I also want to ask. Is it okay if i define my own UUID for two different android devices to communicate each other? I mean, wouldn't it be conflict if I use the same UUID for two different device? –  Jul 7 '14 at 7:24

Your Answer

stackoverflow.com/questions/19630810/android-get-bluetooth-uuid-for-this-device

stackoverflow.com/questions/19630810/android-get-bluetooth-uuid-for-this-device

转载于:https://www.cnblogs.com/pengmn/p/4921509.html

你可能感兴趣的文章
如何让自己变得更加成熟
查看>>
jQuery 入门教程(6): 淡入淡出效果
查看>>
【转载】adb devices 设备名称相同 解决办法
查看>>
informix数据库及数据导入导出
查看>>
最长公共子序列
查看>>
数据公钥加密和认证的介绍
查看>>
编辑器中对象菜单及其子菜单的使用介绍
查看>>
Integer 和 int 有什么区别
查看>>
php 中英文字符分割
查看>>
Docker能够运行任何应用的"PaaS"云
查看>>
Git@OSC 项目推荐 —— MINA 远程调用框架
查看>>
Flex中模态容器和非模态容器的区别
查看>>
在Oracle中查看所有的表
查看>>
二分K均值(bisecting k-means)算法
查看>>
USACO1.1 Your Ride Is Here (ride)
查看>>
汉诺塔问题
查看>>
一个比较好的Linkedin论坛讲述Ubuntu的系统管理
查看>>
ios 代码创建UIToolBar
查看>>
病毒测试网站
查看>>
英语句子收集
查看>>