0

I have a problem. My android code is not compatible with the iOS bluetooth advertising. I read about on the apple documentation, that the advertising was worked between iOS devices.

But I think if the iOS can read it, the android why not? Does the android devices received uuids in a byte array? And how can I parse these? Is it possible?

How can read adverting data on Android device, when iOS use this code:

CBPeripheralManager *manager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
NSArray *uuids = @[[CBUUID UUIDWithString:@"128bit uuudid"],
                   [CBUUID UUIDWithString:@"other 128bit uuudid"],
                   [CBUUID UUIDWithString:@"128bit uuudid"],
                   ....];

NSDictionary *data = @[CBAdvertisementDataLocalNameKey: @"My name",
                       CBAdvertisementDataServiceUUIDsKey: uuids]; 
[manager startAdvertising:data];

I tried scan UUIDs on Android but, it read only the first uuid. How can I read the others?

I use this code for parsing UUIDs on Android, but it is not working.

public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
     ParcelUuid[] uuids = device.getUuids();

     List<UUID> ud = parseUuids(scanRecord);
     if (ud != null) {
          for (UUID u : ud) {
               Timber.v("UUUUID: %s", u);
          }
     }
}

private static List<UUID> parseUuids(byte[] advertisedData) {
        List<UUID> uuids = new ArrayList<UUID>();

    ByteBuffer buffer = ByteBuffer.wrap(advertisedData).order(ByteOrder.LITTLE_ENDIAN);
    while (buffer.remaining() > 2) {
        byte length = buffer.get();
        if (length == 0) break;

        byte type = buffer.get();
        switch (type) {
            case 0x02: // Partial list of 16-bit UUIDs
            case 0x03: // Complete list of 16-bit UUIDs
                while (length >= 2) {
                    uuids.add(UUID.fromString(String.format(
                            "%08x-0000-1000-8000-00805f9b34fb", buffer.getShort())));
                    length -= 2;
                }
                break;

            case 0x06: // Partial list of 128-bit UUIDs
            case 0x07: // Complete list of 128-bit UUIDs
            case 0x15:
                while (length >= 16) {
                    long lsb = buffer.getLong();
                    long msb = buffer.getLong();
                    uuids.add(new UUID(msb, lsb));
                    length -= 16;
                }
                break;

            default:
                buffer.position(buffer.position() + length - 1);
                break;
        }
    }

    return uuids;
}
bvarga
  • 716
  • 6
  • 12
  • The advertisement is limited to 31 bytes so there is no room to place several 128bit UUIDS. You can try to pass `[CBUUID UUIDWithString:@"16bit uuid"]` to the advertising data. – istirbu Jun 18 '15 at 12:04
  • Thanks. It is working. – bvarga Jul 03 '15 at 12:05

0 Answers0