get Bluetooth Device Uuids - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

get Bluetooth Device Uuids

Demo Code


//package com.java2s;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

import android.bluetooth.BluetoothDevice;

import android.os.ParcelUuid;
import android.util.Log;

public class Main {
    private static final String TAG = "BluetoothUtils";
    private static final boolean D = true;

    public static ArrayList<ParcelUuid> getDeviceUuids(
            BluetoothDevice device) {/* w w  w.  j a  va  2  s .  c  o m*/
        ArrayList<ParcelUuid> result = new ArrayList<ParcelUuid>();

        try {
            Method method = device.getClass().getMethod("getUuids", null);
            ParcelUuid[] phoneUuids = (ParcelUuid[]) method.invoke(device,
                    null);
            if (phoneUuids != null) {
                for (ParcelUuid uuid : phoneUuids) {
                    if (D)
                        Log.d(TAG,
                                device.getName() + ": " + uuid.toString());
                    result.add(uuid);
                }
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
            if (D)
                Log.e(TAG, "getDeviceUuids() failed", e);
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            if (D)
                Log.e(TAG, "getDeviceUuids() failed", e);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            if (D)
                Log.e(TAG, "getDeviceUuids() failed", e);
        }

        return result;
    }
}

Related Tutorials