Android - Get Bluetooth UUID for this device

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

Android - Get Bluetooth UUID for this device


up vote 9 down vote favorite

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

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) 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!

android bluetooth uuid android-bluetooth


shareimprove this question

asked Oct 28 ‘13 at 9:12

Ron
5,010954120

 

    

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

add a comment

1 Answer

active
oldest
votes

up vote
13
down vote

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-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

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.


shareimprove this answer

answered Oct 28 ‘13 at 20:36

Stefano S.
16413

 

    

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?
– Ron
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?
– Stefano S.
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.
– Stefano S.
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?
– Ron
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?
– gumuruh
Jul 7 ‘14 at 7:24

show 5 more comments

Your Answer

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

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

时间: 2024-08-07 18:41:51

Android - Get Bluetooth UUID for this device的相关文章

Android as Bluetooth Low Energy Peripherial (GATT server).

I demonstrate how to write a simple BLE peripheral application in Android here. I am bad in Android development, The UI would be very ugly, but the code work: Currently(5/25/2015), the code could be running in Nexus 6 or Nexus 9 only based on my test

深入了解Android蓝牙Bluetooth——《进阶篇》

在 [深入了解Android蓝牙Bluetooth--<基础篇>](http://blog.csdn.net/androidstarjack/article/details/60468468)一篇中我们对蓝牙的各个版本的有了一个认识,蓝牙版本的历程及其优劣式介绍.那么接下来咱们就深入一点继续开车进入BLE的进及篇章. 蓝牙BLE4.x BLE分为三部分: Service Characteristic Descriptor 这三部分都用UUID作为唯一标识符.UUID为这种格式:0000ffe1

Android学习Bluetooth总结

蓝牙是API level 5 就有的一个技术 由于我对这个技术感兴趣 就学习了下 将学到的知识和大家分享下 客户端 private static final UUID MY_UUID_SECURE = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66"); //安全的private static final UUID MY_UUID_INSECURE = UUID.fromString("8ce255c0-200a-1

android -- 蓝牙 bluetooth (一) 入门

前段时间在 网上看了一些关于android蓝牙的文章,发现大部分是基于老版本(4.1以前含4.1)的源码,虽然无碍了解蓝牙的基本原理和工作流程,但对着4.2.2的代码看起来总是有些遗憾.所以针对4.2.2版本代码整理下相关知识,当然蓝牙工作的主干流程是没有变的,上电.加载驱动这些动作少不了的,只是这些功能的实现代码位置变了不少.希望本文可以让大家对android4.2的蓝牙部分代码有一个初步的了解.         正文开始前,先明确代码版本:android  jellyBean 4.2.2,后

android -- 蓝牙 bluetooth (三)搜索蓝牙

接上篇打开蓝牙继续,来一起看下蓝牙搜索的流程,触发蓝牙搜索的条件形式上有两种,一是在蓝牙设置界面开启蓝牙会直接开始搜索,另一个是先打开蓝牙开关在进入蓝牙设置界面也会触发搜索,也可能还有其它触发方式,但最后都要来到BluetoothSettngs.java的startScanning(),我们分析的起点也从这里开始,起步代码如下 [cpp] view plaincopy private void updateContent(int bluetoothState, boolean scanState

深入了解Android蓝牙Bluetooth ——《总结篇》

在我的上两篇博文中讲解了有关android蓝牙的认识以及API的相关的介绍,蓝牙BLE的搜索,连接以及读取. 没有了解的童鞋们请参考: 深入了解Android蓝牙Bluetooth--<基础篇> 深入了解Android蓝牙Bluetooth--<进阶篇> 目前项目中的效果图: 接下来我们就对蓝牙BLE4.0进行一下总结. 蓝牙API Android ble 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用,如果手机系统版本API level

android -- 蓝牙 bluetooth (四)OPP文件传输

在前面android -- 蓝牙 bluetooth (一) 入门文章结尾中提到了会按四个方面来写这系列的文章,前面已写了蓝牙打开和蓝牙搜索,这次一起来看下蓝牙文件分享的流程,也就是蓝牙应用opp目录下的代码,作为蓝牙最基本的一个功能,这部分的代码在之前的版本中就已经有了,新旧版本代码对比很多类名都是一样的,这一部分新东西不多,写在这里帮助大家梳理下流程吧. 有没有这种感觉,智能手机的普及让我们提高了一点对蓝牙的关注,手机间使用蓝牙互传文件应该是最常用的应用之一,手机与电脑也可以通过蓝牙做同样的

android -- 蓝牙 bluetooth (五)接电话与听音乐

前段时间似乎所有的事情都赶在一起,回家.集体出游.出差,折腾了近一个月,终于算暂时清静了,但清静只是暂时,估计马上又要出差了,所以赶紧把蓝牙这一部分的文章了结下,按之前提到的目录,本文是关于蓝牙接打电话和听音乐的流程分析,对应蓝牙HFP/A2DP的profile,由于这部分也算是蓝牙的经典功能,所以代码流程并不是很复杂,当然不复杂仅是对于代码调用流程而言,对于HFP/A2DP协议相关的东东还没有精力去看,其难易程序也无法评价.下面从两个点HFP与A2DP来展开本文的代码跟踪: 正文开始之前,先说

Android Developer -- Bluetooth篇 开发实例之一

第一步:声明Bluetooth Permissions <!-- 设置蓝牙访问权限 --> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 第二步:获取BluetoothAdapter,判断该设备是否支持蓝牙 Bl