Tim
Tim

Reputation: 1606

Get Company ID values of Bluetooth device

How I can use android.bluetooth.BluetoothAssignedNumbers. I want get Company ID values of Bluetooth device. I can not found any examples about it.

Upvotes: 0

Views: 1399

Answers (2)

Rufus
Rufus

Reputation: 21

result.getScanRecord().getBytes()

The company identifier is the two bytes after the byte that has the value -1.

The position changes depending on the the device so you just have to loop through the byte array.

byte[] bytes = result.getScanRecord().getBytes();
String companyID = "";

for(int i = 0; i < bytes.length; i++) {
   if(bytes[i] == -1) {
      companyID = companyID + String.format("%02X", bytes[i+1]) + String.format("%02X", bytes[i+2]);
      break;
   }
}

Upvotes: 1

mir
mir

Reputation: 381

from here https://stackoverflow.com/a/39896379/1739847

ScanRecord scanRecord = scanResult.getScanRecord();
SparseArray<byte[]> manufacturerData = scanRecord.getManufacturerSpecificData();
for(int i = 0; i < manufacturerData .size(); i++){
    int manufacturerId = manufacturerData.keyAt(i);
}

Upvotes: 1

Related Questions