Example usage for android.bluetooth BluetoothDevice getType

List of usage examples for android.bluetooth BluetoothDevice getType

Introduction

In this page you can find the example usage for android.bluetooth BluetoothDevice getType.

Prototype

@RequiresPermission(Manifest.permission.BLUETOOTH)
public int getType() 

Source Link

Document

Get the Bluetooth device type of the remote device.

Usage

From source file:Main.java

public static String printDevice(BluetoothDevice device) {
    return String.format("%s; %s; %s; %s", device.getAddress(), device.getName(), device.getType(),
            device.getBluetoothClass());
}

From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java

/**
 * for log./*from   w  w  w.j  a va 2s  . com*/
 * @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, "=============================================");
}