Java Code Examples for android.os.ParcelUuid#fromString()
The following examples show how to use
android.os.ParcelUuid#fromString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScanFilterTest.java From Android-Scanner-Compat-Library with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testsetServiceDataFilter() { byte[] setServiceData = new byte[] { 0x50, 0x64 }; ParcelUuid serviceDataUuid = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"); ScanFilter filter = filterBuilder.setServiceData(serviceDataUuid, setServiceData).build(); assertTrue("service data filter fails", filter.matches(scanResult)); byte[] emptyData = new byte[0]; filter = filterBuilder.setServiceData(serviceDataUuid, emptyData).build(); assertTrue("service data filter fails", filter.matches(scanResult)); byte[] prefixData = new byte[] { 0x50 }; filter = filterBuilder.setServiceData(serviceDataUuid, prefixData).build(); assertTrue("service data filter fails", filter.matches(scanResult)); byte[] nonMatchData = new byte[] { 0x51, 0x64 }; byte[] mask = new byte[] { (byte) 0x00, (byte) 0xFF }; filter = filterBuilder.setServiceData(serviceDataUuid, nonMatchData, mask).build(); assertTrue("partial service data filter fails", filter.matches(scanResult)); filter = filterBuilder.setServiceData(serviceDataUuid, nonMatchData).build(); assertFalse("service data filter fails", filter.matches(scanResult)); }
Example 2
Source File: JsonDeserializer.java From mobly-bundled-snippets with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static AdvertiseData jsonToBleAdvertiseData(JSONObject jsonObject) throws JSONException { AdvertiseData.Builder builder = new AdvertiseData.Builder(); if (jsonObject.has("IncludeDeviceName")) { builder.setIncludeDeviceName(jsonObject.getBoolean("IncludeDeviceName")); } if (jsonObject.has("IncludeTxPowerLevel")) { builder.setIncludeTxPowerLevel(jsonObject.getBoolean("IncludeTxPowerLevel")); } if (jsonObject.has("ServiceData")) { JSONArray serviceData = jsonObject.getJSONArray("ServiceData"); for (int i = 0; i < serviceData.length(); i++) { JSONObject dataSet = serviceData.getJSONObject(i); ParcelUuid parcelUuid = ParcelUuid.fromString(dataSet.getString("UUID")); builder.addServiceUuid(parcelUuid); if (dataSet.has("Data")) { byte[] data = Base64.decode(dataSet.getString("Data"), Base64.DEFAULT); builder.addServiceData(parcelUuid, data); } } } if (jsonObject.has("ManufacturerData")) { JSONObject manufacturerData = jsonObject.getJSONObject("ManufacturerData"); int manufacturerId = manufacturerData.getInt("ManufacturerId"); byte[] manufacturerSpecificData = Base64.decode(jsonObject.getString("ManufacturerSpecificData"), Base64.DEFAULT); builder.addManufacturerData(manufacturerId, manufacturerSpecificData); } return builder.build(); }
Example 3
Source File: ScanRecordTest.java From Android-Scanner-Compat-Library with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testParser() { byte[] scanRecord = new byte[] { 0x02, 0x01, 0x1a, // advertising flags 0x05, 0x02, 0x0b, 0x11, 0x0a, 0x11, // 16 bit service uuids 0x04, 0x09, 0x50, 0x65, 0x64, // name 0x02, 0x0A, (byte) 0xec, // tx power level 0x05, 0x16, 0x0b, 0x11, 0x50, 0x64, // service data 0x05, (byte) 0xff, (byte) 0xe0, 0x00, 0x02, 0x15, // manufacturer specific data 0x03, 0x50, 0x01, 0x02, // an unknown data type won't cause trouble }; ScanRecord data = ScanRecord.parseFromBytes(scanRecord); assertEquals(0x1a, data.getAdvertiseFlags()); ParcelUuid uuid1 = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB"); ParcelUuid uuid2 = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"); assertTrue(data.getServiceUuids().contains(uuid1)); assertTrue(data.getServiceUuids().contains(uuid2)); assertEquals("Ped", data.getDeviceName()); assertEquals(-20, data.getTxPowerLevel()); assertTrue(data.getManufacturerSpecificData().get(0x00E0) != null); assertArrayEquals(new byte[] { 0x02, 0x15 }, data.getManufacturerSpecificData().get(0x00E0)); assertTrue(data.getServiceData().containsKey(uuid2)); assertArrayEquals(new byte[] { 0x50, 0x64 }, data.getServiceData().get(uuid2)); }
Example 4
Source File: ScanFilterUtils.java From android-beacon-library with Apache License 2.0 | 5 votes |
public List<ScanFilter> createScanFiltersForBeaconParsers(List<BeaconParser> beaconParsers) { List<ScanFilter> scanFilters = new ArrayList<ScanFilter>(); // for each beacon parser, make a filter expression that includes all its desired // hardware manufacturers for (BeaconParser beaconParser: beaconParsers) { List<ScanFilterData> sfds = createScanFilterDataForBeaconParser(beaconParser); for (ScanFilterData sfd: sfds) { ScanFilter.Builder builder = new ScanFilter.Builder(); if (sfd.serviceUuid != null) { // Use a 16 bit service UUID in a 128 bit form String serviceUuidString = String.format("0000%04X-0000-1000-8000-00805f9b34fb", sfd.serviceUuid); String serviceUuidMaskString = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"; ParcelUuid parcelUuid = ParcelUuid.fromString(serviceUuidString); ParcelUuid parcelUuidMask = ParcelUuid.fromString(serviceUuidMaskString); if (LogManager.isVerboseLoggingEnabled()) { LogManager.d(TAG, "making scan filter for service: "+serviceUuidString+" "+parcelUuid); LogManager.d(TAG, "making scan filter with service mask: "+serviceUuidMaskString+" "+parcelUuidMask); } builder.setServiceUuid(parcelUuid, parcelUuidMask); } else { builder.setServiceUuid(null); builder.setManufacturerData((int) sfd.manufacturer, sfd.filter, sfd.mask); } ScanFilter scanFilter = builder.build(); if (LogManager.isVerboseLoggingEnabled()) { LogManager.d(TAG, "Set up a scan filter: "+scanFilter); } scanFilters.add(scanFilter); } } return scanFilters; }
Example 5
Source File: BleScanner.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 4 votes |
public static int getDeviceType(@NonNull BlePeripheral blePeripheral) { int type = kDeviceType_Unknown; ScanRecord scanRecord = blePeripheral.getScanRecord(); if (scanRecord != null) { byte[] advertisedData = scanRecord.getBytes(); // Check if is an iBeacon ( 0x02, 0x01, a flag byte, 0x1A, 0xFF, manufacturer (2bytes), 0x02, 0x15) final boolean isBeacon = advertisedData != null && advertisedData.length > 8 && advertisedData[0] == 0x02 && advertisedData[1] == 0x01 && advertisedData[3] == 0x1A && advertisedData[4] == (byte) 0xFF && advertisedData[7] == 0x02 && advertisedData[8] == 0x15; if (isBeacon) { type = kDeviceType_Beacon; } else { // Check if is an URIBeacon final byte[] kUriBeaconPrefix = {0x03, 0x03, (byte) 0xD8, (byte) 0xFE}; final boolean isUriBeacon = advertisedData != null && advertisedData.length > 7 && Arrays.equals(Arrays.copyOf(advertisedData, kUriBeaconPrefix.length), kUriBeaconPrefix) && advertisedData[5] == 0x16 && advertisedData[6] == kUriBeaconPrefix[2] && advertisedData[7] == kUriBeaconPrefix[3]; if (isUriBeacon) { type = kDeviceType_UriBeacon; } else { // Check if Uart is contained in the uuids boolean isUart = false; List<ParcelUuid> serviceUuids = scanRecord.getServiceUuids(); if (serviceUuids != null) { ParcelUuid uartUuid = ParcelUuid.fromString("6e400001-b5a3-f393-e0a9-e50e24dcca9e"); for (ParcelUuid serviceUuid : serviceUuids) { if (serviceUuid.equals(uartUuid)) { isUart = true; break; } } } if (isUart) { type = kDeviceType_Uart; } } } } return type; }
Example 6
Source File: ScanFilterTest.java From Android-Scanner-Compat-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testReadWriteParcel() { ScanFilter filter = filterBuilder.build(); testReadWriteParcelForFilter(filter); filter = filterBuilder.setDeviceName("Ped").build(); testReadWriteParcelForFilter(filter); filter = filterBuilder.setDeviceAddress("11:22:33:44:55:66").build(); testReadWriteParcelForFilter(filter); filter = filterBuilder.setServiceUuid(ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB")) .build(); testReadWriteParcelForFilter(filter); filter = filterBuilder.setServiceUuid(ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB"), ParcelUuid.fromString("FFFFFFF0-FFFF-FFFF-FFFF-FFFFFFFFFFFF")).build(); testReadWriteParcelForFilter(filter); byte[] serviceData = new byte[] { 0x50, 0x64 }; ParcelUuid serviceDataUuid = ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"); filter = filterBuilder.setServiceData(serviceDataUuid, serviceData).build(); testReadWriteParcelForFilter(filter); filter = filterBuilder.setServiceData(serviceDataUuid, new byte[0]).build(); testReadWriteParcelForFilter(filter); byte[] serviceDataMask = new byte[] { (byte) 0xFF, (byte) 0xFF }; filter = filterBuilder.setServiceData(serviceDataUuid, serviceData, serviceDataMask).build(); testReadWriteParcelForFilter(filter); byte[] manufacturerData = new byte[] { 0x02, 0x15 }; int manufacturerId = 0xE0; filter = filterBuilder.setManufacturerData(manufacturerId, manufacturerData).build(); testReadWriteParcelForFilter(filter); filter = filterBuilder.setServiceData(serviceDataUuid, new byte[0]).build(); testReadWriteParcelForFilter(filter); byte[] manufacturerDataMask = new byte[] { (byte) 0xFF, (byte) 0xFF }; filter = filterBuilder.setManufacturerData(manufacturerId, manufacturerData, manufacturerDataMask) .build(); testReadWriteParcelForFilter(filter); }
Example 7
Source File: BleUuidUtils.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Obtains a ParcelUuid from Short style value. * * @param uuidShortValue the Short style UUID value. * @return an UUID instance. */ @NonNull public static ParcelUuid parcelFromShortValue(final int uuidShortValue) { return ParcelUuid.fromString(UUID_LONG_STYLE_PREFIX + String.format("%04X", uuidShortValue & 0xffff) + UUID_LONG_STYLE_POSTFIX); }