@Override public String getMacAddress() { return bluetoothDevice.getAddress(); }
@Override public String toString() { return "RxBleDeviceImpl{" + "bluetoothDevice=" + bluetoothDevice.getName() + '(' + bluetoothDevice.getAddress() + ')' + '}'; } }
@Override protected BleException provideException(DeadObjectException deadObjectException) { return new BleDisconnectedException(deadObjectException, bluetoothDevice.getAddress(), BleDisconnectedException.UNKNOWN_STATUS); } }
private void appendDeviceHeader(BluetoothDevice device, StringBuilder descriptionBuilder) { descriptionBuilder .append("--------------- ====== Printing peripheral content ====== ---------------\n") .append("PERIPHERAL ADDRESS: ").append(device.getAddress()).append('\n') .append("PERIPHERAL NAME: ").append(device.getName()).append('\n') .append("-------------------------------------------------------------------------"); }
BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { Toast.makeText(this, "At least one paired bluetooth device found", Toast.LENGTH_SHORT).show(); // TODO at this point you'd have to iterate these devices and check if any of them is a wearable (HOW?) for (BluetoothDevice device : pairedDevices) { Log.d("YOUR_TAG", "Paired device: "+ device.getName() + ", with address: " + device.getAddress()); } } else { Toast.makeText(this, "No paired bluetooth devices found", Toast.LENGTH_SHORT).show(); }
mBluetoothAdapter.startDiscovery(); mReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); //Finding devices if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // Add the name and address to an array adapter to show in a ListView mArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } }; IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); registerReceiver(mReceiver, filter);
public BluetoothDeviceAssert hasAddress(String address) { isNotNull(); String actualAddress = actual.getAddress(); assertThat(actualAddress) // .overridingErrorMessage("Expected address <%s> but was <%s>.", address, actualAddress) // .isEqualTo(address); return this; }
private static String getMacAddress(@Nullable BluetoothGatt gatt) { return (gatt != null && gatt.getDevice() != null) ? gatt.getDevice().getAddress() : null; }
@Override protected BleException provideException(DeadObjectException deadObjectException) { return new BleDisconnectedException(deadObjectException, bluetoothGatt.getDevice().getAddress(), BleDisconnectedException.UNKNOWN_STATUS); }
@Override protected BleException provideException(DeadObjectException deadObjectException) { return new BleDisconnectedException(deadObjectException, bluetoothGatt.getDevice().getAddress(), BleDisconnectedException.UNKNOWN_STATUS); }
@Override protected BleException provideException(DeadObjectException deadObjectException) { return new BleDisconnectedException(deadObjectException, bluetoothGatt.getDevice().getAddress(), BleDisconnectedException.UNKNOWN_STATUS); } }
@Override public void showDevice(BluetoothDevice device) { setTitle(getString(R.string.app_name)+" "+device.getAddress()); getSupportFragmentManager() .beginTransaction() .hide(roster) .add(android.R.id.content, DeviceFragment.newInstance(device)) .addToBackStack(null) .commit(); } }
@Override public Set<RxBleDevice> getBondedDevices() { guardBluetoothAdapterAvailable(); Set<RxBleDevice> rxBleDevices = new HashSet<>(); Set<BluetoothDevice> bluetoothDevices = rxBleAdapterWrapper.getBondedDevices(); for (BluetoothDevice bluetoothDevice : bluetoothDevices) { rxBleDevices.add(getBleDevice(bluetoothDevice.getAddress())); } return rxBleDevices; }
protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); public boolean setCharacteristicNotification(BluetoothDevice device, UUID serviceUuid, UUID characteristicUuid, boolean enable) { if (IS_DEBUG) Log.d(TAG, "setCharacteristicNotification(device=" + device.getName() + device.getAddress() + ", UUID=" + characteristicUuid + ", enable=" + enable + " )"); BluetoothGatt gatt = mGattInstances.get(device.getAddress()); //I just hold the gatt instances I got from connect in this HashMap BluetoothGattCharacteristic characteristic = gatt.getService(serviceUuid).getCharacteristic(characteristicUuid); gatt.setCharacteristicNotification(characteristic, enable); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID); descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 }); return gatt.writeDescriptor(descriptor); //descriptor write operation successfully started? }
@Override public ObservableSource<RxBleConnection> call() throws Exception { if (isConnected.compareAndSet(false, true)) { return connector.prepareConnection(options) .doFinally(new Action() { @Override public void run() { isConnected.set(false); } }); } else { return Observable.error(new BleAlreadyConnectedException(bluetoothDevice.getAddress())); } } });
private RxBleScanResult convertToPublicScanResult(RxBleInternalScanResultLegacy scanResult) { final BluetoothDevice bluetoothDevice = scanResult.getBluetoothDevice(); final RxBleDevice bleDevice = getBleDevice(bluetoothDevice.getAddress()); return new RxBleScanResult(bleDevice, scanResult.getRssi(), scanResult.getScanRecord()); }
mac = device.getAddress();
@Override public ScanResult apply(RxBleInternalScanResult rxBleInternalScanResult) { return new ScanResult( deviceProvider.getBleDevice(rxBleInternalScanResult.getBluetoothDevice().getAddress()), rxBleInternalScanResult.getRssi(), rxBleInternalScanResult.getTimestampNanos(), rxBleInternalScanResult.getScanCallbackType(), rxBleInternalScanResult.getScanRecord() ); } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { RxBleLog.d("onConnectionStateChange newState=%d status=%d", newState, status); nativeCallbackDispatcher.notifyNativeConnectionStateCallback(gatt, status, newState); super.onConnectionStateChange(gatt, status, newState); bluetoothGattProvider.updateBluetoothGatt(gatt); if (isDisconnectedOrDisconnecting(newState)) { disconnectionRouter.onDisconnectedException(new BleDisconnectedException(gatt.getDevice().getAddress(), status)); } else if (status != BluetoothGatt.GATT_SUCCESS) { disconnectionRouter.onGattConnectionStateException( new BleGattException(gatt, status, BleGattOperationType.CONNECTION_STATE) ); } connectionStatePublishRelay.accept(mapConnectionStateToRxBleConnectionStatus(newState)); }
if (!mDistinctPacketDetector.isPacketDistinct(scanData.device.getAddress(), scanData.scanRecord)) { LogManager.i(TAG, "Non-distinct packets detected in a single scan. Restarting scans unecessary.");