1

I could not find any standard API in Android to check for SPP profile support. Is there any way (direct or indirect) by which one can determine this programmatically? One indirect method that I could think of was to use BluetoothAdapter.listenUsingRfcommWithServiceRecord to start an RFCOMM server socket, which should (presumably) succeed if the device supports SPP and fail otherwise. Would this work, or is there a better/correct way?

Thinkisto
  • 432
  • 1
  • 4
  • 13

1 Answers1

0
String sspUuid = "00001101-0000-1000-8000-00805f9b34fb";
boolean uuidExists = false;
ParcelUuid[] uuids = {};

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
 uuids = device.getUuids()
  } else {
 Method getUuidsMethod = device.getClass().getMethod("getUuids", null);
 uuids = (ParcelUuid[]) getUuidsMethod.invoke(device, null);
 }

for (ParcelUuid uuid : uuids) {
 if (uuid.toString().equalsIgnoreCase(sspUuid)) {
   uuidExists = true;
   break;
 }
}

if (uuidExists) {
  socket = device.createRfcommSocketToServiceRecord(UUID.fromString(sspUuid));   
}

For anyone still wondering I use this that works on older and new version of android. Don't forget to add exception handling.

Charles Semaan
  • 304
  • 2
  • 13