Java Code Examples for no.nordicsemi.android.support.v18.scanner.ScanResult#getScanRecord()

The following examples show how to use no.nordicsemi.android.support.v18.scanner.ScanResult#getScanRecord() . 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: NrfMeshRepository.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onScanResult(final int callbackType, final ScanResult result) {
    //In order to connectToProxy to the correct device, the hash advertised in the advertisement data should be matched.
    //This is to make sure we connectToProxy to the same device as device addresses could change after provisioning.
    final ScanRecord scanRecord = result.getScanRecord();
    if (scanRecord != null) {
        final byte[] serviceData = Utils.getServiceData(result, MESH_PROXY_UUID);
        if (serviceData != null) {
            if (mMeshManagerApi.isAdvertisedWithNodeIdentity(serviceData)) {
                final ProvisionedMeshNode node = mProvisionedMeshNode;
                if (mMeshManagerApi.nodeIdentityMatches(node, serviceData)) {
                    stopScan();
                    mConnectionState.postValue("Provisioned node found");
                    onProvisionedDeviceFound(node, new ExtendedBluetoothDevice(result));
                }
            }
        }
    }
}
 
Example 2
Source File: ExtendedBluetoothDevice.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ExtendedBluetoothDevice(final ScanResult scanResult, final MeshBeacon beacon) {
    this.scanResult = scanResult;
    this.device = scanResult.getDevice();
    final ScanRecord scanRecord = scanResult.getScanRecord();
    if(scanRecord != null) {
        this.name = scanRecord.getDeviceName();
    }
    this.rssi = scanResult.getRssi();
    this.beacon = beacon;
}
 
Example 3
Source File: DeviceListAdapter.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * If such device exists on the bonded device list, this method does nothing. If not then the device is updated (rssi value) or added.
 * 
 * @param results scan results
 */
public void update(final List<ScanResult> results) {
	for (final ScanResult result : results) {
		final ExtendedBluetoothDevice device = findDevice(result);
		if (device == null) {
			mDevices.add(new ExtendedBluetoothDevice(result));
		} else {
			device.name = result.getScanRecord() != null ? result.getScanRecord().getDeviceName() : null;
			device.rssi = result.getRssi();
		}
	}
	notifyDataSetChanged();
}
 
Example 4
Source File: DeviceListAdapter.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Updates the list of not bonded devices.
 * @param results list of results from the scanner
 */
public void update(@NonNull final List<ScanResult> results) {
	for (final ScanResult result : results) {
		final ExtendedBluetoothDevice device = findDevice(result);
		if (device == null) {
			listValues.add(new ExtendedBluetoothDevice(result));
		} else {
			device.name = result.getScanRecord() != null ? result.getScanRecord().getDeviceName() : null;
			device.rssi = result.getRssi();
		}
	}
	notifyDataSetChanged();
}
 
Example 5
Source File: ExtendedBluetoothDevice.java    From Android-nRF-BLE-Joiner with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ExtendedBluetoothDevice(final ScanResult result) {
	mBluetoothDevice = result.getDevice();
	if (result.getScanRecord() != null)
		mName = result.getScanRecord().getDeviceName();
	else
		mName = mBluetoothDevice.getName();
}
 
Example 6
Source File: DevicesLiveData.java    From Android-nRF-Blinky with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("SimplifiableIfStatement")
private boolean matchesUuidFilter(@NonNull final ScanResult result) {
	if (!filterUuidRequired)
		return true;

	final ScanRecord record = result.getScanRecord();
	if (record == null)
		return false;

	final List<ParcelUuid> uuids = record.getServiceUuids();
	if (uuids == null)
		return false;

	return uuids.contains(FILTER_UUID);
}
 
Example 7
Source File: DiscoveredBluetoothDevice.java    From Android-nRF-Blinky with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Updates the device values based on the scan result.
 *
 * @param scanResult the new received scan result.
 */
public void update(@NonNull final ScanResult scanResult) {
	lastScanResult = scanResult;
	name = scanResult.getScanRecord() != null ?
			scanResult.getScanRecord().getDeviceName() : null;
	previousRssi = rssi;
	rssi = scanResult.getRssi();
	if (highestRssi < rssi)
		highestRssi = rssi;
}
 
Example 8
Source File: DeviceListAdapter.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * If such device exists on the bonded device list, this method does nothing. If not then the device is updated (rssi value) or added.
 * 
 * @param results scan results
 */
public void update(final List<ScanResult> results) {
	for (final ScanResult result : results) {
		final ExtendedBluetoothDevice device = findDevice(result);
		if (device == null) {
			mDevices.add(new ExtendedBluetoothDevice(result));
		} else {
			device.name = result.getScanRecord() != null ? result.getScanRecord().getDeviceName() : null;
			device.rssi = result.getRssi();
		}
	}
	notifyDataSetChanged();
}
 
Example 9
Source File: DiscoveredBluetoothDevice.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the device values based on the scan result.
 *
 * @param scanResult the new received scan result.
 */
public void update(final ScanResult scanResult) {
    lastScanResult = scanResult;
    name = scanResult.getScanRecord() != null ?
            scanResult.getScanRecord().getDeviceName() : null;
    previousRssi = rssi;
    rssi = scanResult.getRssi();
    if (highestRssi < rssi)
        highestRssi = rssi;
}
 
Example 10
Source File: FilterUtils.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
public static boolean isAirDrop(final ScanResult result) {
    if (result != null && result.getScanRecord() != null) {
        final ScanRecord record = result.getScanRecord();

        // iPhones and iMacs advertise with AirDrop packets
        final byte[] appleData = record.getManufacturerSpecificData(COMPANY_ID_APPLE);
        return appleData != null && appleData.length > 1 && appleData[0] == 0x10;
    }
    return false;
}
 
Example 11
Source File: FilterUtils.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("RedundantIfStatement")
public static boolean isBeacon(final ScanResult result) {
    if (result != null && result.getScanRecord() != null) {
        final ScanRecord record = result.getScanRecord();

        final byte[] appleData = record.getManufacturerSpecificData(COMPANY_ID_APPLE);
        if (appleData != null) {
            // iBeacons
            if (appleData.length == 23 && appleData[0] == 0x02 && appleData[1] == 0x15)
                return true;
        }

        final byte[] nordicData = record.getManufacturerSpecificData(COMPANY_ID_NORDIC_SEMI);
        if (nordicData != null) {
            // Nordic Beacons
            if (nordicData.length == 23 && nordicData[0] == 0x02 && nordicData[1] == 0x15)
                return true;
        }

        final byte[] microsoftData = record.getManufacturerSpecificData(COMPANY_ID_MICROSOFT);
        if (microsoftData != null) {
            // Microsoft Advertising Beacon
            if (microsoftData[0] == 0x01) // Scenario Type = Advertising Beacon
                return true;
        }

        // Eddystone
        final byte[] eddystoneData = record.getServiceData(EDDYSTONE_UUID);
        if (eddystoneData != null)
            return true;
    }

    return false;
}
 
Example 12
Source File: DevicesLiveData.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("SimplifiableIfStatement")
private boolean matchesUuidFilter(final ScanResult result) {
    if (!mFilterUuidRequired)
        return true;

    final ScanRecord record = result.getScanRecord();
    if (record == null)
        return false;

    final List<ParcelUuid> uuids = record.getServiceUuids();
    if (uuids == null)
        return false;

    return uuids.contains(FILTER_UUID);
}
 
Example 13
Source File: ScannerRepository.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateScannerLiveData(final ScanResult result) {
    final ScanRecord scanRecord = result.getScanRecord();
    if (scanRecord != null) {
        if (scanRecord.getBytes() != null) {
            final byte[] beaconData = mMeshManagerApi.getMeshBeaconData(scanRecord.getBytes());
            if (beaconData != null) {
                mScannerLiveData.deviceDiscovered(result, mMeshManagerApi.getMeshBeacon(beaconData));
            } else {
                mScannerLiveData.deviceDiscovered(result);
            }
            mScannerStateLiveData.deviceFound();
        }
    }
}
 
Example 14
Source File: ExtendedBluetoothDevice.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ExtendedBluetoothDevice(final ScanResult scanResult) {
    this.scanResult = scanResult;
    this.device = scanResult.getDevice();
    final ScanRecord scanRecord = scanResult.getScanRecord();
    if(scanRecord != null) {
        this.name = scanRecord.getDeviceName();
    }
    this.rssi = scanResult.getRssi();
}
 
Example 15
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 16
Source File: ExtendedBluetoothDevice.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ExtendedBluetoothDevice(final ScanResult scanResult) {
	this.device = scanResult.getDevice();
	this.name = scanResult.getScanRecord() != null ? scanResult.getScanRecord().getDeviceName() : null;
	this.rssi = scanResult.getRssi();
}
 
Example 17
Source File: ExtendedBluetoothDevice.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ExtendedBluetoothDevice(@NonNull final ScanResult scanResult) {
	this.device = scanResult.getDevice();
	this.name = scanResult.getScanRecord() != null ? scanResult.getScanRecord().getDeviceName() : null;
	this.rssi = scanResult.getRssi();
	this.isBonded = false;
}
 
Example 18
Source File: ExtendedBluetoothDevice.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ExtendedBluetoothDevice(final ScanResult scanResult) {
	this.device = scanResult.getDevice();
	this.name = scanResult.getScanRecord() != null ? scanResult.getScanRecord().getDeviceName() : null;
	this.rssi = scanResult.getRssi();
}