mickeywilko
mickeywilko

Reputation: 117

Get UUID of local low energy bluetooth device in Android

I'm trying to access the UUID of low energy bluetooth devices in Android, ultimately to post the string to a web API.

Here's my code that works fine at toasting the local name and mac address:

private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver(){

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();

        if(BluetoothDevice.ACTION_FOUND.equals(action)) {

            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            String sMac     = device.getAddress();
            String sName    = device.getName();
            String sUUID    = ""; //HELP!

            Toast toast = Toast.makeText(getApplicationContext(), "Mac: " + sMac + " - Name: " + sName + " - UUID: " + sUUID, Toast.LENGTH_SHORT);
            toast.show();

        }

    }

};

Can anyone help with this?

Upvotes: 1

Views: 9431

Answers (2)

Kiran
Kiran

Reputation: 129

Bluetooth UUIDs (Universally Unique Identifier) are assigned to Bluetooth services, characteristics, descriptors etc. to identify each and every Bluetooth attribute. It's not like a MAC address i.e. per device you have one ID. So when you do discovery for services of other connected Bluetooth devices using API such as BluetoothGattObj.discoverServices(), it discovers a set of services, characteristics, descriptors etc. supported on other Bluetooth devices.

Using the above code snippet submitted by you won't give you any Bluetooth UUIDs.

There is a sample Bluetooth Low Energy application available in the Android-SDK that when you download through Google's Android website and the relative path for the same may be ..\adt-bundle-windows-x86-xxxx\sdk\samples\android-xx\connectivity\BluetoothLeGatt. Please refer the same.

Upvotes: 1

Cody Caughlan
Cody Caughlan

Reputation: 32748

There can be multiple UUIDs - which represent the BLE Characteristics of that device.

http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids()

You can iterate over the array of UUIDs and grab the one you want.

If you're looking for a unique identifier for a single device then you want the MAC address which you can get via BluetoothDevice.getAddress()

Upvotes: 2

Related Questions