Android - Get Bluetooth UUID for this device

來源:互聯網
上載者:User

標籤:

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 favorite7

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

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

Android - Get Bluetooth UUID for this device

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.