android.os.ParcelUuid Java Examples

The following examples show how to use android.os.ParcelUuid. 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: BluetoothAdapter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Get the UUIDs supported by the local Bluetooth adapter.
 *
 * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
 *
 * @return the UUIDs supported by the local Bluetooth Adapter.
 * @hide
 */
public ParcelUuid[] getUuids() {
    if (getState() != STATE_ON) {
        return null;
    }
    try {
        mServiceLock.readLock().lock();
        if (mService != null) {
            return mService.getUuids();
        }
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
    } finally {
        mServiceLock.readLock().unlock();
    }
    return null;
}
 
Example #2
Source File: ScanFilter.java    From Android-Scanner-Compat-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ScanFilter(@Nullable final String name, @Nullable final String deviceAddress,
				   @Nullable final ParcelUuid uuid, @Nullable final ParcelUuid uuidMask,
				   @Nullable final ParcelUuid serviceDataUuid, @Nullable final byte[] serviceData,
				   @Nullable final byte[] serviceDataMask, final int manufacturerId,
				   @Nullable final byte[] manufacturerData,
				   @Nullable final byte[] manufacturerDataMask) {
	this.deviceName = name;
	this.serviceUuid = uuid;
	this.serviceUuidMask = uuidMask;
	this.deviceAddress = deviceAddress;
	this.serviceDataUuid = serviceDataUuid;
	this.serviceData = serviceData;
	this.serviceDataMask = serviceDataMask;
	this.manufacturerId = manufacturerId;
	this.manufacturerData = manufacturerData;
	this.manufacturerDataMask = manufacturerDataMask;
}
 
Example #3
Source File: MockScanResultProvider.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
MockScanResultProvider(int numberOfMockResults, int minRssi, int maxRssi){
    rnd = new Random(System.currentTimeMillis());
    scanResults = new ArrayList<>(numberOfMockResults);
    serviceDataMap = new HashMap<>();
    byte[] randomData = new byte[16];
    rnd.nextBytes(randomData);
    serviceDataMap.put(new ParcelUuid(UUID.fromString("adabfb00-6e7d-4601-bda2-bffaa68956ba")), randomData);
    for(int i=0; i < numberOfMockResults; i++) {
        ScanResult result = Mockito.mock(ScanResult.class);
        BluetoothDevice device = Mockito.mock(BluetoothDevice.class);
        ScanRecord record = Mockito.mock(ScanRecord.class);
        Mockito.when(device.getAddress()).thenReturn(randomMACAddress());
        Mockito.when(device.getName()).thenReturn("foobar-" + String.valueOf(i));
        Mockito.when(result.getDevice()).thenReturn(device);
        Mockito.when(result.getRssi()).thenReturn(-1 * (rnd.nextInt(Math.abs(minRssi) + 1 - Math.abs(maxRssi)) + Math.abs(maxRssi)));
        Assert.assertTrue("Rssi is less than zero", result.getRssi() < 0);
        Mockito.when(record.getDeviceName()).thenReturn("foobar-" + String.valueOf(i));
        Mockito.when(record.getServiceData()).thenReturn(serviceDataMap);
        scanResults.add(result);
    }
}
 
Example #4
Source File: ScanFilter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the uuid pattern is contained in a list of parcel uuids.
 *
 * @hide
 */
public static boolean matchesServiceUuids(ParcelUuid uuid, ParcelUuid parcelUuidMask,
        List<ParcelUuid> uuids) {
    if (uuid == null) {
        return true;
    }
    if (uuids == null) {
        return false;
    }

    for (ParcelUuid parcelUuid : uuids) {
        UUID uuidMask = parcelUuidMask == null ? null : parcelUuidMask.getUuid();
        if (matchesServiceUuid(uuid.getUuid(), uuidMask, parcelUuid.getUuid())) {
            return true;
        }
    }
    return false;
}
 
Example #5
Source File: ScanRecordImplCompat.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
public ScanRecordImplCompat(
        @Nullable List<ParcelUuid> serviceUuids,
        SparseArray<byte[]> manufacturerData,
        Map<ParcelUuid, byte[]> serviceData,
        int advertiseFlags,
        int txPowerLevel,
        String localName,
        byte[] bytes
) {
    this.serviceUuids = serviceUuids;
    this.manufacturerSpecificData = manufacturerData;
    this.serviceData = serviceData;
    this.deviceName = localName;
    this.advertiseFlags = advertiseFlags;
    this.txPowerLevel = txPowerLevel;
    this.bytes = bytes;
}
 
Example #6
Source File: BluetoothGattCharacteristic.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private BluetoothGattCharacteristic(Parcel in) {
    mUuid = ((ParcelUuid) in.readParcelable(null)).getUuid();
    mInstance = in.readInt();
    mProperties = in.readInt();
    mPermissions = in.readInt();
    mKeySize = in.readInt();
    mWriteType = in.readInt();

    mDescriptors = new ArrayList<BluetoothGattDescriptor>();

    ArrayList<BluetoothGattDescriptor> descs =
            in.createTypedArrayList(BluetoothGattDescriptor.CREATOR);
    if (descs != null) {
        for (BluetoothGattDescriptor desc : descs) {
            desc.setCharacteristic(this);
            mDescriptors.add(desc);
        }
    }
}
 
Example #7
Source File: NrfMeshRepository.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Starts reconnecting to the device
 */
private void startScan() {
    if (mIsScanning)
        return;

    mIsScanning = true;
    // Scanning settings
    final ScanSettings settings = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
            // Refresh the devices list every second
            .setReportDelay(0)
            // Hardware filtering has some issues on selected devices
            .setUseHardwareFilteringIfSupported(false)
            // Samsung S6 and S6 Edge report equal value of RSSI for all devices. In this app we ignore the RSSI.
            /*.setUseHardwareBatchingIfSupported(false)*/
            .build();

    // Let's use the filter to scan only for Mesh devices
    final List<ScanFilter> filters = new ArrayList<>();
    filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid((MESH_PROXY_UUID))).build());

    final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
    scanner.startScan(filters, settings, scanCallback);
    Log.v(TAG, "Scan started");
    mHandler.postDelayed(mScannerTimeout, 20000);
}
 
Example #8
Source File: BluetoothUtilImpl.java    From android-ponewheel with MIT License 6 votes vote down vote up
void scanLeDevice(final boolean enable) {
    Timber.d("scanLeDevice enable = " + enable);
    if (enable) {
        mScanning = true;
        List<ScanFilter> filters_v2 = new ArrayList<>();
        ScanFilter scanFilter = new ScanFilter.Builder()
                .setServiceUuid(ParcelUuid.fromString(OWDevice.OnewheelServiceUUID))
                .build();
        filters_v2.add(scanFilter);
        //c03f7c8d-5e96-4a75-b4b6-333d36230365
        mBluetoothLeScanner.startScan(filters_v2, settings, mScanCallback);
    } else {
        mScanning = false;
        mBluetoothLeScanner.stopScan(mScanCallback);
        // added 10/23 to try cleanup
        mBluetoothLeScanner.flushPendingScanResults(mScanCallback);
    }
    mainActivity.invalidateOptionsMenu();
}
 
Example #9
Source File: BluetoothUuid.java    From physical-web with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if there any common ParcelUuids in uuidA and uuidB.
 *
 * @param uuidA - List of ParcelUuids
 * @param uuidB - List of ParcelUuids
 */
public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    if (uuidA == null && uuidB == null) {
        return true;
    }
    if (uuidA == null) {
        return uuidB.length == 0 ? true : false;
    }
    if (uuidB == null) {
        return uuidA.length == 0 ? true : false;
    }
    HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (uuidSet.contains(uuid)) {
            return true;
        }
    }
    return false;
}
 
Example #10
Source File: BluetoothUuid.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if all the ParcelUuids in ParcelUuidB are present in
 * ParcelUuidA
 *
 * @param uuidA - Array of ParcelUuidsA
 * @param uuidB - Array of ParcelUuidsB
 */
public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    if (uuidA == null && uuidB == null) return true;

    if (uuidA == null) {
        return uuidB.length == 0;
    }

    if (uuidB == null) return true;

    HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (!uuidSet.contains(uuid)) return false;
    }
    return true;
}
 
Example #11
Source File: BluetoothUuid.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if there any common ParcelUuids in uuidA and uuidB.
 *
 * @param uuidA - List of ParcelUuids
 * @param uuidB - List of ParcelUuids
 */
public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    if (uuidA == null && uuidB == null) return true;

    if (uuidA == null) {
        return uuidB.length == 0;
    }

    if (uuidB == null) {
        return uuidA.length == 0;
    }

    HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (uuidSet.contains(uuid)) return true;
    }
    return false;
}
 
Example #12
Source File: BluetoothUuid.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if all the ParcelUuids in ParcelUuidB are present in ParcelUuidA
 *
 * @param uuidA - Array of ParcelUuidsA
 * @param uuidB - Array of ParcelUuidsB
 */
public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    if (uuidA == null && uuidB == null) {
        return true;
    }
    if (uuidA == null) {
        return uuidB.length == 0;
    }
    if (uuidB == null) {
        return true;
    }
    HashSet<ParcelUuid> uuidSet = new HashSet<>(Arrays.asList(uuidA));
    for (ParcelUuid uuid : uuidB) {
        if (!uuidSet.contains(uuid)) {
            return false;
        }
    }
    return true;
}
 
Example #13
Source File: GattServerActivity.java    From sample-bluetooth-le-gattserver with Apache License 2.0 6 votes vote down vote up
/**
 * Begin advertising over Bluetooth that this device is connectable
 * and supports the Current Time Service.
 */
private void startAdvertising() {
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    mBluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mBluetoothLeAdvertiser == null) {
        Log.w(TAG, "Failed to create advertiser");
        return;
    }

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(TimeProfile.TIME_SERVICE))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
 
Example #14
Source File: MainActivity.java    From bluetooth with Apache License 2.0 6 votes vote down vote up
void discover() {
    mBluetoothLeScanner = BluetoothAdapter.getDefaultAdapter().getBluetoothLeScanner();

    ScanFilter filter = new ScanFilter.Builder()
        .setServiceUuid( new ParcelUuid(UUID.fromString( getString(R.string.ble_uuid ) ) ) )
        .build();
    List<ScanFilter> filters = new ArrayList<ScanFilter>();
    filters.add( filter );

    ScanSettings settings = new ScanSettings.Builder()
        .setScanMode( ScanSettings.SCAN_MODE_LOW_LATENCY )
        .build();
    mBluetoothLeScanner.startScan(filters, settings, mScanCallback);
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            mBluetoothLeScanner.stopScan(mScanCallback);
        }
    }, 10000);
}
 
Example #15
Source File: ScanFilter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Set partial filter on service data. For any bit in the mask, set it to 1 if it needs to
 * match the one in service data, otherwise set it to 0 to ignore that bit.
 * <p>
 * The {@code serviceDataMask} must have the same length of the {@code serviceData}.
 *
 * @throws IllegalArgumentException If {@code serviceDataUuid} is null or {@code
 * serviceDataMask} is {@code null} while {@code serviceData} is not or {@code
 * serviceDataMask} and {@code serviceData} has different length.
 */
public Builder setServiceData(ParcelUuid serviceDataUuid,
        byte[] serviceData, byte[] serviceDataMask) {
    if (serviceDataUuid == null) {
        throw new IllegalArgumentException("serviceDataUuid is null");
    }
    if (mServiceDataMask != null) {
        if (mServiceData == null) {
            throw new IllegalArgumentException(
                    "serviceData is null while serviceDataMask is not null");
        }
        // Since the mServiceDataMask is a bit mask for mServiceData, the lengths of the two
        // byte array need to be the same.
        if (mServiceData.length != mServiceDataMask.length) {
            throw new IllegalArgumentException(
                    "size mismatch for service data and service data mask");
        }
    }
    mServiceDataUuid = serviceDataUuid;
    mServiceData = serviceData;
    mServiceDataMask = serviceDataMask;
    return this;
}
 
Example #16
Source File: BlePeripheralUart.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public static boolean isUartAdvertised(@NonNull BlePeripheral blePeripheral) {
    List<ParcelUuid> serviceUuids = blePeripheral.getScanRecord().getServiceUuids();
    boolean found = false;

    if (serviceUuids != null) {
        int i = 0;
        while (i < serviceUuids.size() && !found) {
            found = serviceUuids.get(i).getUuid().equals(kUartServiceUUID);
            i++;
        }
    }
    return found;
}
 
Example #17
Source File: AdvertiseData.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Add service data to advertise data.
 *
 * @param serviceDataUuid 16-bit UUID of the service the data is associated with
 * @param serviceData Service data
 * @throws IllegalArgumentException If the {@code serviceDataUuid} or {@code serviceData} is
 * empty.
 */
public Builder addServiceData(ParcelUuid serviceDataUuid, byte[] serviceData) {
    if (serviceDataUuid == null || serviceData == null) {
        throw new IllegalArgumentException(
                "serviceDataUuid or serviceDataUuid is null");
    }
    mServiceData.put(serviceDataUuid, serviceData);
    return this;
}
 
Example #18
Source File: ScanRecordImplCompatLocal.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the service data byte array associated with the {@code serviceUuid}. Returns
 * {@code null} if the {@code serviceDataUuid} is not found.
 */
@Nullable
public byte[] getServiceData(ParcelUuid serviceDataUuid) {
    if (serviceDataUuid == null) {
        return null;
    }
    return serviceData.get(serviceDataUuid);
}
 
Example #19
Source File: BluetoothUuidCompat.java    From AndroidBleManager with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if ParcelUuid is present in uuidArray
 *
 * @param uuidArray - Array of ParcelUuids
 * @param uuid
 */
public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
    if ((uuidArray == null || uuidArray.length == 0) && uuid == null)
        return true;

    if (uuidArray == null)
        return false;

    for (ParcelUuid element : uuidArray) {
        if (element.equals(uuid)) return true;
    }
    return false;
}
 
Example #20
Source File: ScanFilter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ScanFilter(String name, String deviceAddress, ParcelUuid uuid,
        ParcelUuid uuidMask, ParcelUuid serviceDataUuid,
        byte[] serviceData, byte[] serviceDataMask,
        int manufacturerId, byte[] manufacturerData, byte[] manufacturerDataMask) {
    mDeviceName = name;
    mServiceUuid = uuid;
    mServiceUuidMask = uuidMask;
    mDeviceAddress = deviceAddress;
    mServiceDataUuid = serviceDataUuid;
    mServiceData = serviceData;
    mServiceDataMask = serviceDataMask;
    mManufacturerId = manufacturerId;
    mManufacturerData = manufacturerData;
    mManufacturerDataMask = manufacturerDataMask;
}
 
Example #21
Source File: MainActivity.java    From rubik-robot with MIT License 5 votes vote down vote up
public void connectBluetooth() {
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    if (!mBluetoothAdapter.isEnabled()) {
        Toast.makeText(this, "Enable Bluetooth and pair", Toast.LENGTH_LONG).show();
        return;
    }
    BluetoothDevice device = mBluetoothAdapter.getRemoteDevice("98:D3:31:30:3B:D8");
    for (BluetoothDevice x : mBluetoothAdapter.getBondedDevices()) {
        Log.d("Main", "Address: " + x.getAddress());
        for (ParcelUuid uuid : x.getUuids()) {
            Log.d("Main", "parceluuid:" + uuid.toString());
        }
    }
    try {
        mBluetoothAdapter.cancelDiscovery();

        BluetoothSocket socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"));
        socket.connect();

        mRobotScheduler = new RobotScheduler(socket.getInputStream(), socket.getOutputStream(), 10);
        Toast.makeText(this, "Connected to arduino", Toast.LENGTH_SHORT).show();

        mMapper = new SlightlyMoreAdvancedMapper();

    } catch (IOException e) {
        Log.d("Main", "Exception connecting to bluetooth: ", e);
    }
}
 
Example #22
Source File: BluetoothUuid.java    From EFRConnect-android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if ParcelUuid is present in uuidArray
 *
 * @param uuidArray - Array of ParcelUuids
 * @param uuid
 */
public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
    if ((uuidArray == null || uuidArray.length == 0) && uuid == null) {
        return true;
    }
    if (uuidArray == null) {
        return false;
    }
    for (ParcelUuid element : uuidArray) {
        if (element.equals(uuid)) {
            return true;
        }
    }
    return false;
}
 
Example #23
Source File: ScanRecord.java    From Android-BLE with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the service data byte array associated with the {@code serviceUuid}. Returns
 * {@code null} if the {@code serviceDataUuid} is not found.
 */
@Nullable
public byte[] getServiceData(ParcelUuid serviceDataUuid) {
    if (serviceDataUuid == null) {
        return null;
    }
    return mServiceData.get(serviceDataUuid);
}
 
Example #24
Source File: Utils.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
public static byte[] getServiceData(@NonNull final ScanResult result, @NonNull final UUID serviceUuid) {
    final ScanRecord scanRecord = result.getScanRecord();
    if (scanRecord != null) {
        return scanRecord.getServiceData(new ParcelUuid((serviceUuid)));
    }
    return null;
}
 
Example #25
Source File: BluetoothUuid.java    From EFRConnect-android with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
 */
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
}
 
Example #26
Source File: WebContentsImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public WebContents createFromParcel(Parcel source) {
    Bundle bundle = source.readBundle();

    // Check the version.
    if (bundle.getLong(PARCEL_VERSION_KEY, -1) != 0) return null;

    // Check that we're in the same process.
    ParcelUuid parcelUuid = bundle.getParcelable(PARCEL_PROCESS_GUARD_KEY);
    if (sParcelableUUID.compareTo(parcelUuid.getUuid()) != 0) return null;

    // Attempt to retrieve the WebContents object from the native pointer.
    return nativeFromNativePtr(bundle.getLong(PARCEL_WEBCONTENTS_KEY));
}
 
Example #27
Source File: ScanFilterUtils.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
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 #28
Source File: AbstractHOGPServer.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * アドバタイジングを開始します.
 */
private void startAdvertising() {
    if (DEBUG) {
        Log.d(TAG, "startAdvertising");
    }

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            // set up advertising setting
            final AdvertiseSettings advertiseSettings = new AdvertiseSettings.Builder()
                    .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
                    .setConnectable(true)
                    .setTimeout(0)
                    .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
                    .build();

            // set up advertising data
            final AdvertiseData advertiseData = new AdvertiseData.Builder()
                    .setIncludeTxPowerLevel(false)
                    .setIncludeDeviceName(true)
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            // set up scan result
            final AdvertiseData scanResult = new AdvertiseData.Builder()
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_DEVICE_INFORMATION.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BLE_HID.toString()))
                    .addServiceUuid(ParcelUuid.fromString(SERVICE_BATTERY.toString()))
                    .build();

            mBluetoothLeAdvertiser.startAdvertising(advertiseSettings, advertiseData, scanResult, mAdvertiseCallback);
        }
    });
}
 
Example #29
Source File: ScanFilter.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
ScanFilter(String name, String deviceAddress, ParcelUuid uuid,
           ParcelUuid uuidMask, ParcelUuid serviceDataUuid,
           byte[] serviceData, byte[] serviceDataMask,
           int manufacturerId, byte[] manufacturerData, byte[] manufacturerDataMask) {
    mDeviceName = name;
    mServiceUuid = uuid;
    mServiceUuidMask = uuidMask;
    mDeviceAddress = deviceAddress;
    mServiceDataUuid = serviceDataUuid;
    mServiceData = serviceData;
    mServiceDataMask = serviceDataMask;
    mManufacturerId = manufacturerId;
    mManufacturerData = manufacturerData;
    mManufacturerDataMask = manufacturerDataMask;
}
 
Example #30
Source File: BluetoothUuid.java    From physical-web with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
 *
 * @param parcelUuid
 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
 */
public static boolean is16BitUuid(ParcelUuid parcelUuid) {
    UUID uuid = parcelUuid.getUuid();
    if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
        return false;
    }
    return (uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L;
}