Java Code Examples for android.bluetooth.le.ScanResult#getRssi()

The following examples show how to use android.bluetooth.le.ScanResult#getRssi() . 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: MainActivity.java    From Mi365Locker with GNU General Public License v3.0 9 votes vote down vote up
@Override
public void onScanResult(int callbackType, ScanResult result) {
    super.onScanResult(callbackType, result);

    BluetoothDevice newDevice = result.getDevice();

    int newRssi = result.getRssi();
    String device_name = newDevice.getName();
    String device_address = newDevice.getAddress();
    if(device_name == null)
    {
        return;
    }

    DeviceConnection dev = devices_connections.get(device_address);
    if(dev != null) {
        devicesAdapter.update(newDevice, newRssi, dev.getState());
    } else {
        devicesAdapter.update(newDevice, newRssi, RxBleConnection.RxBleConnectionState.DISCONNECTED);
    }

    String mDeviceAddress = newDevice.getAddress();
    add_device_to_attack(mDeviceAddress);
}
 
Example 2
Source File: ScanResultCompat.java    From EFRConnect-android with Apache License 2.0 5 votes vote down vote up
public static ScanResultCompat from(Object lollipopScanResult) {
    if (lollipopScanResult == null) {
        return null;
    }

    ScanResult sr = (ScanResult) lollipopScanResult;
    ScanResultCompat retVal = new ScanResultCompat();
    retVal.device = sr.getDevice();
    retVal.rssi = sr.getRssi();
    retVal.scanRecord = ScanRecordCompat.from(sr.getScanRecord());
    retVal.advertData = ScanRecordParser.getAdvertisements(sr.getScanRecord().getBytes());
    retVal.timestampNanos = sr.getTimestampNanos();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        retVal.isConnectable = sr.isConnectable();
        retVal.isLegacy = sr.isLegacy();
        retVal.dataStatus = sr.getDataStatus();
        retVal.primaryPhy = sr.getPrimaryPhy();
        retVal.secondaryPhy = sr.getSecondaryPhy();
        retVal.advertisingSetID = sr.getAdvertisingSid();
        retVal.TxPower = sr.getTxPower();
        retVal.periodicAdvertisingInterval = sr.getPeriodicAdvertisingInterval();
    } else {
        retVal.isLegacy = true;
        retVal.isConnectable = true;
    }
    return retVal;

}
 
Example 3
Source File: BleManager.java    From FastBle with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public BleDevice convertBleDevice(ScanResult scanResult) {
    if (scanResult == null) {
        throw new IllegalArgumentException("scanResult can not be Null!");
    }
    BluetoothDevice bluetoothDevice = scanResult.getDevice();
    int rssi = scanResult.getRssi();
    ScanRecord scanRecord = scanResult.getScanRecord();
    byte[] bytes = null;
    if (scanRecord != null)
        bytes = scanRecord.getBytes();
    long timestampNanos = scanResult.getTimestampNanos();
    return new BleDevice(bluetoothDevice, rssi, bytes, timestampNanos);
}
 
Example 4
Source File: ScanResultCompat.java    From AndroidBleManager with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
ScanResultCompat(ScanResult result) {
    mDevice = new BluetoothLeDevice(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes(), System.currentTimeMillis());//result.getTimestampNanos()
    mScanRecord = new ScanRecordCompat(result.getScanRecord());
    mRssi = result.getRssi();
    mTimestampNanos = System.currentTimeMillis();//result.getTimestampNanos();
}
 
Example 5
Source File: EddystoneScannerService.java    From nearby-beacons with MIT License 5 votes vote down vote up
private void processResult(ScanResult result) {
    ScanRecord record = result.getScanRecord();
    if (record == null) {
        Log.w(TAG, "Invalid scan record.");
        return;
    }
    final byte[] data = record.getServiceData(UID_SERVICE);
    if (data == null) {
        Log.w(TAG, "Invalid Eddystone scan result.");
        return;
    }

    final String deviceAddress = result.getDevice().getAddress();
    final int rssi = result.getRssi();
    byte frameType = data[0];
    switch (frameType) {
        case TYPE_UID:
            mCallbackHandler.post(new Runnable() {
                @Override
                public void run() {
                    processUidPacket(deviceAddress, rssi, data);
                }
            });
            break;
        case TYPE_TLM:
        case TYPE_URL:
            //Do nothing, ignoring these
            return;
        default:
            Log.w(TAG, "Invalid Eddystone scan result.");
    }
}
 
Example 6
Source File: InternalScanResultCreator.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@RequiresApi(21 /* Build.VERSION_CODES.LOLLIPOP */)
public RxBleInternalScanResult create(ScanResult result) {
    final ScanRecordImplNativeWrapper scanRecord = new ScanRecordImplNativeWrapper(result.getScanRecord());
    return new RxBleInternalScanResult(result.getDevice(), result.getRssi(), result.getTimestampNanos(), scanRecord,
            ScanCallbackType.CALLBACK_TYPE_BATCH);
}
 
Example 7
Source File: InternalScanResultCreator.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@RequiresApi(21 /* Build.VERSION_CODES.LOLLIPOP */)
public RxBleInternalScanResult create(int callbackType, ScanResult result) {
    final ScanRecordImplNativeWrapper scanRecord = new ScanRecordImplNativeWrapper(result.getScanRecord());
    return new RxBleInternalScanResult(result.getDevice(), result.getRssi(), result.getTimestampNanos(), scanRecord,
            toScanCallbackType(callbackType));
}
 
Example 8
Source File: LollipopPeripheral.java    From react-native-ble-manager with Apache License 2.0 4 votes vote down vote up
public LollipopPeripheral(ReactContext reactContext, ScanResult result) {
	super(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes(), reactContext);
	this.advertisingData = result.getScanRecord();
	this.scanResult = result;
}