get Bluetooth Device Uuids - Android android.bluetooth

Android examples for android.bluetooth:Bluetooth

Description

get Bluetooth Device Uuids

Demo Code

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

import android.bluetooth.BluetoothDevice;
import android.os.ParcelUuid;

public class Main {
  public static ArrayList<ParcelUuid> getDeviceUuids(BluetoothDevice device) {
    ArrayList<ParcelUuid> result = new ArrayList<ParcelUuid>();
    try {//  w ww.  ja v a2  s .  co m
      Method method = device.getClass().getMethod("getUuids", null);
      ParcelUuid[] phoneUuids = (ParcelUuid[]) method.invoke(device, null);
      if (phoneUuids != null) {
        for (ParcelUuid uuid : phoneUuids) {
          result.add(uuid);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return result;
  }

}

Related Tutorials