List of usage examples for android.bluetooth BluetoothDevice getUuids
@RequiresPermission(Manifest.permission.BLUETOOTH)
public ParcelUuid[] getUuids()
From source file:org.chromium.ChromeBluetooth.java
private Collection<String> getUuidStringsFromDevice(BluetoothDevice device) { Set<String> uuidStrings = new HashSet<String>(); ParcelUuid[] uuids = device.getUuids(); if (uuids != null) { for (ParcelUuid uuid : uuids) { uuidStrings.add(uuid.toString()); }// ww w . j a v a 2 s. c o m } return uuidStrings; }
From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java
/** * for log.//from ww w .ja v a 2s.c o m * @param device * @param adRecords */ private void printScanDevices(BluetoothDevice device, HashMap<Integer, AdRecord> adRecords) { Log.d(TAG, "onLeScan() ============================================="); Log.d(TAG, "onLeScan: uuid:" + (device.getUuids() != null ? device.getUuids().toString() : "null") + ", name = " + device.getName()); Log.d(TAG, "onLeScan: address:" + device.getAddress()); Log.d(TAG, "onLeScan: bluetooth class:" + device.getBluetoothClass()); Log.d(TAG, "onLeScan: type:" + device.getType()); String str = ""; byte[] values; for (Map.Entry<Integer, AdRecord> entry : adRecords.entrySet()) { Integer type = entry.getKey(); AdRecord adRecord = entry.getValue(); if (adRecord != null) { switch (type) { case AdRecord.TYPE_FLAGS: int flags = adRecord.getValue()[0] & 0x0FF; str = ""; if ((flags & 0x01) > 0) { str += "'LE Limited Discoverable Mode' "; } if ((flags & (0x01 << 1)) > 0) { str += "'LE General Discoverable Mode' "; } if ((flags & (0x01 << 2)) > 0) { str += "'BR/EDR Not Supported' "; } if ((flags & (0x01 << 3)) > 0) { str += "'Simultaneous LE and BR/EDR to Same Device Capacble (Controller)' "; } if ((flags & (0x01 << 4)) > 0) { str += "'Simultaneous LE and BR/EDR to Same Device Capacble (Host)' "; } Log.d(TAG, "onLeScan: TYPE_FLAGS = " + str); break; case AdRecord.TYPE_UUID16_INC: case AdRecord.TYPE_UUID16: { ArrayList<String> uuids = DataParser.getUint16StringArray(adRecord.getValue()); int i = 0; for (String uuid : uuids) { Log.d(TAG, "onLeScan: TYPE_UUID16(_INC)[" + (++i) + "] = " + uuid); } break; } case AdRecord.TYPE_UUID32_INC: case AdRecord.TYPE_UUID32: { ArrayList<String> uuids = DataParser.getUint32StringArray(adRecord.getValue()); int i = 0; for (String uuid : uuids) { Log.d(TAG, "onLeScan: TYPE_UUID32(_INC)[" + (++i) + "] = " + uuid); } break; } case AdRecord.TYPE_UUID128_INC: case AdRecord.TYPE_UUID128: { ArrayList<String> uuids = DataParser.getUint128StringArray(adRecord.getValue()); int i = 0; for (String uuid : uuids) { Log.d(TAG, "onLeScan: TYPE_UUID128(_INC)[" + (++i) + "] = " + uuid); } break; } case AdRecord.TYPE_NAME_SHORT: str = DataParser.getString(adRecord.getValue()); Log.d(TAG, "onLeScan: TYPE_NAME_SHORT = " + str); break; case AdRecord.TYPE_NAME: str = DataParser.getString(adRecord.getValue()); Log.d(TAG, "onLeScan: TYPE_NAME = " + str); break; case AdRecord.TYPE_TRANSMITPOWER: Log.d(TAG, "onLeScan: TYPE_TRANSMITPOWER = " + DataParser.getInt8(adRecord.getValue()[0])); break; case AdRecord.TYPE_SERVICEDATA: values = adRecord.getValue(); String uuid = DataParser.getUint16String(Arrays.copyOfRange(values, 0, 2)); Log.d(TAG, "onLeScan: TYPE_SERVICEDATA uuid = " + uuid); str = DataParser.getHexString(Arrays.copyOfRange(values, 2, values.length)); Log.d(TAG, "onLeScan: TYPE_SERVICEDATA hexstringdata = " + str); break; case AdRecord.TYPE_APPEARANCE: str = DataParser.getUint16String(adRecord.getValue()); Log.d(TAG, "onLeScan: TYPE_APPEARANCE = " + str); break; case AdRecord.TYPE_VENDOR_SPECIFIC: values = adRecord.getValue(); // https://www.bluetooth.org/en-us/specification/assigned-numbers/company-identifiers str = DataParser.getUint16String(Arrays.copyOfRange(values, 0, 2)); Log.d(TAG, "onLeScan: TYPE_VENDOR_SPECIFIC company = " + str); if ("004C".equals(str)) { // Apple Inc int offset = 2; int data_type = values[offset++]; int data_length = values[offset++]; if (data_type == 0x02) { // iBeacon // https://www.uncinc.nl/nl/blog/finding-out-the-ibeacons-specifications // http://www.warski.org/blog/2014/01/how-ibeacons-work/ // http://developer.iotdesignshop.com/tutorials/bluetooth-le-and-ibeacon-primer/ // String uuid = parseUUID(this.parseHex(Arrays.copyOfRange(value, offset, offset + 16), true)); // offset += 16; // ad.apple.ibeacon.major = parseHex(Arrays.copyOfRange(value, offset, offset + 2), true); // offset += 2; // ad.apple.ibeacon.minor = parseHex(Arrays.copyOfRange(value, offset, offset + 2), true); // offset += 2; // ad.tx_power = this.parseSignedNumber(value[offset]); } else { // ad.apple.vendor = this.parseHex(Arrays.copyOfRange(value, offset - 2, offset + data_length), true); } } else { // ad.vendor = this.parseHex(Arrays.copyOfRange(value, i, i + len - 1), true); } break; } } } Log.d(TAG, "============================================="); }
From source file:com.improvelectronics.sync.android.SyncStreamingService.java
private void updatePairedDevices() { Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); if (pairedDevices == null || pairedDevices.size() == 0) return;//from w ww .j a v a2 s . co m if (DEBUG) Log.d(TAG, "searching for paired Syncs"); mPairedDevices.clear(); for (BluetoothDevice device : pairedDevices) { if (device.getName() != null && device.getName().equals("Sync")) { if (DEBUG) Log.d(TAG, "found a Boogie Board Sync"); mPairedDevices.add(device); } } // Connect to the first device that was found in the list of paired devices. if (mPairedDevices.size() > 0 && mState != STATE_CONNECTED) { BluetoothDevice device = mPairedDevices.get(0); // Device must first be checked to see if it has the most up to date firmware. // This check is done by ensuring the device has all the correct UUIDs. // If it doesn't have the CONNECT_UUID then the firmware is not the latest. boolean foundUuid = false; for (ParcelUuid uuid : device.getUuids()) { if (uuid.getUuid().equals(CONNECT_UUID)) foundUuid = true; } if (!foundUuid) { showUpdateFirmwareNotification(); } } }